PHP - Set HTTP_COOKIE Header

by
Jeremy Canfield |
Updated: December 13 2021
| 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