PHP program

Create or Retrieve a cookie. The program can set as below :

<?php

   

  /*

    setcookie(name, value, expire, path, domain, secure, httponly);

    Only the name parameter is required.

    All other parameters are optional.

  */

 

  $cookie_name = "language";

  $cookie_value = "Java";

 

  setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");

 

  if(!isset($_COOKIE[$cookie_name]))

  {

      echo "Cookie named '" . $cookie_name . "' is not set!<br>";

      echo "Reload to view cookies.";

  }

  else

  {

      echo "Cookie named '" . $cookie_name . "' is set!<br>";

      echo "Value is: " . $_COOKIE[$cookie_name];

  }

?>

OUTPUT

Cookie named 'language' is not set! Reload to view cookies. ---------------------------------------- Output after Page Reload ---------------------------------------- Cookie named 'language' is set! Value is: Java
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s