Forum Moderators: coopster
Here is the set cookie code:
* authuser.php *
if ($num!=0){
$cookie_name ="auth";
$cookie_value ="ok";
$cookie_expire ="0";
$cookie_domain ="127.0.0.1";
setcookie($cookie_name,$cookie_value,$cookie_expi
re,"/", $cookie_domain,0);
$display_block ="
<p><strong>Secret Menu:</strong></p>
<ul>
<li><a href=\"secretA.php\">secret page A</a>
<li><a href=\"secretB.php\">secret page B</a>
</ul>";
---------------------------------------------
* secretA.php and secretB.php *
<?
if ($_COOKIE[auth] == "ok") {
$msg = "<P>Welcome to secret page A, authorized user!</p>";
} else {
echo "<p>Not Working</p>";
}
?>
When I click the links for either page I get 'Not Working' rather than the message. I've checked browser settings. This code is straight from the author- so I'm not too sure what's going on.
Thanks-
Try it with just
setcookie($cookie_name,$cookie_value, 0);
That's a basic cookie. Your domain main be throwing it off.
Also, if you use Mozilla, you can view cookies very easily. Whenever I'm working with cookies, I use mozilla to test.
Content-type: text/html\n\n
You might want to make sure the content type header is after your cookie sets.
Neither the PERSISTENT CLIENT STATE HTTP COOKIES Specification [wp.netscape.com], RFC2109 - HTTP State Management Mechanism (obsolete) [faqs.org], RFC2965 - HTTP State Management Mechanism [faqs.org], nor RFC2616 - Hypertext Transfer Protocol -- HTTP/1.1 [faqs.org] seem to suggest that. Quite to the contrary the latter explicitly states:
The order in which header fields with differing field names are received is not significant.
Andreas
var_dump(_$COOKIE);
Actually, are you sure your version of php supports the new _$COOKIE variable? (They only became available in version 4.1.0 onward)
Try looking at the older $HTTP_COOKIE_VARS array too,
var_dump ($HTTP_COOKIE_VARS);