Bootstrap FreeKB - PHP - Set HTTP_COOKIE Header
PHP - Set HTTP_COOKIE Header

Updated:   |  PHP articles

The Set-Cookie header can be used to create the HTTP_COOKIE header. Let's say page1.php contains the following. Navigating to http://www.freekb.net/page1.php should start a session, create the HTTP_COOKIE header with a value of "foo", and then redirect to http://www.freekb.net/page2.php.

<?php
  session_start();
  header("Set-Cookie: foo");
  header("Location:http://stage.freekb.net/page2.php");
?>

 

Let's say page2.php contains the following.

<?php
  session_start();
  foreach ( $_SERVER as $key=>$value ) {
    print "\$_SERVER[\"$key\"] == $value<br/>";
  }
?>

 

Or like this.

echo $_SERVER['HTTP_COOKIE'];

 

Something like this should be displayed http://www.freekb.net/page2.php.

$_SERVER["HTTP_COOKIE"] == foo

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d06067 in the box below so that we can be sure you are a human.