Re: sending session cookie before redirect
A horsie named 11abacus demonstrated surprising intelligence and its
ability to use morse code on Tue, 09 Sep 2003 11:05:14 -0500 when it
tapped <1a2a8cd7.03090 90805.3aa475c5@ posting.google. com> with its hoof:
[color=blue]
> "Set-Cookie:" and "Location:" HTTP headers don't mix well with most web
> browsers [...][/color]
The following script, which uses both setcookie() and
the location header, works with these web browsers:
Lynx, Firebird, Mozilla, Galeon, Konqueror, wget.
wget doesn't seem to like cookies that have square
brackets [] in them, but it did accept and use
the 'captain' cookie.
<?php
// PHP 4.0.5
error_reporting (E_ALL);
$g = & $HTTP_GET_VARS;
$c = & $HTTP_COOKIE_VA RS;
$s = & $HTTP_SERVER_VA RS;
$ttl = time() + 86400;
header('Cache-control: no-cache');
header('Pragma: no-cache');
if (!isset($g['show'])):
setcookie('user[cindy]', '8', $ttl, '/');
setcookie('user[mark]', '4', $ttl, '/');
setcookie('user[jarmain]', 41, $ttl, '/');
setcookie('capt ain', 'mark', $ttl, '/');
header("Locatio n: http://$s[HTTP_HOST]$s[PHP_SELF]?show=1");
exit();
else:
?>
<title> A Cookie Test </title>
<p> This page sets and displays some cookies.
</p>
<?php
echo "<pre>\n";
print_r($c);
echo "</pre>\n";
endif;
?>
I don't have access to MSIE; perhaps someone can test
with that one.
A horsie named 11abacus demonstrated surprising intelligence and its
ability to use morse code on Tue, 09 Sep 2003 11:05:14 -0500 when it
tapped <1a2a8cd7.03090 90805.3aa475c5@ posting.google. com> with its hoof:
[color=blue]
> "Set-Cookie:" and "Location:" HTTP headers don't mix well with most web
> browsers [...][/color]
The following script, which uses both setcookie() and
the location header, works with these web browsers:
Lynx, Firebird, Mozilla, Galeon, Konqueror, wget.
wget doesn't seem to like cookies that have square
brackets [] in them, but it did accept and use
the 'captain' cookie.
<?php
// PHP 4.0.5
error_reporting (E_ALL);
$g = & $HTTP_GET_VARS;
$c = & $HTTP_COOKIE_VA RS;
$s = & $HTTP_SERVER_VA RS;
$ttl = time() + 86400;
header('Cache-control: no-cache');
header('Pragma: no-cache');
if (!isset($g['show'])):
setcookie('user[cindy]', '8', $ttl, '/');
setcookie('user[mark]', '4', $ttl, '/');
setcookie('user[jarmain]', 41, $ttl, '/');
setcookie('capt ain', 'mark', $ttl, '/');
header("Locatio n: http://$s[HTTP_HOST]$s[PHP_SELF]?show=1");
exit();
else:
?>
<title> A Cookie Test </title>
<p> This page sets and displays some cookies.
</p>
<?php
echo "<pre>\n";
print_r($c);
echo "</pre>\n";
endif;
?>
I don't have access to MSIE; perhaps someone can test
with that one.
Comment