Re: Question about cookies

From: Date: Mon, 26 Jun 2000 23:22:30 +0000
Subject: Re: Question about cookies
Groups: php.general 
Request: Send a blank email to php-general+get-3241@lists.php.net to get a copy of this message
: I want to create some scripting in which a user can access for 1 minute, : after the minute has expired he has to relogin. Things are configured : using a cookie. Why such a short time period? Your server time and the time on their computer clock is probably out by at least a few seconds, so when you factor in delays with HTTP requests, then there is only a very slim margin of time in which they will be able to use this particular page. I also don't understand your code. It works like so: * if there is no cookie, remove their login details * if there are no login details, as for their login details * store a cookie I think your code needs a bit of a rewrite to look more like so: <?php # this is uneccessary. #if (!$testcookie) { #unset($PHP_AUTH_USER); #} # changed this slightly (so we are not testing # undefined variables, a bad thing (and a warning in PHP4)): if (!isset($PHP_AUTH_USER) && !$PHP_AUTH_USER) { Header("WWW-authenticate: basic realm=\"Testsite\""); Header("HTTP/1.0 401 Unauthorized"); echo "<body bgcolor=#ffffff>Cancel... (not logged in).\n"; exit; } # this is new else { setcookie ("testcookie", "foobar",time()+60); /* expire in 1 minute */ echo "logged in"; # and so is this } ?> -- -- Stephen D C -- Auckland, New Zealand -- http://stephenc.cjb.net/ --

« previous php.general (#3241) next »