[CLUE-Tech] PHP Sessions and Cookies: Brain Cramp
Jed S. Baer
thag at frii.com
Sat Oct 12 22:38:03 MDT 2002
On Sat, 12 Oct 2002 21:42:51 -0600
Jeffery Cann <fabian at jefferycann.com> wrote:
> Jed,
>
> I think the cookie should be set when you do the redirect. Are you
> doing this?
>
> header( "redirect URL" );
header("location: $PATH/main.php");
> Also, check the session.cookie_lifetime set to in your php.ini?
It's 0. That's "session lifetime", IIRC.
> Finally, when I wonder about cookies, I will telnet to my web box and do
> a GET on the URL, so I can view the headers outside of the browser.
> This will confirm whether the cookie is being sent by the server or if
> you have some browser weirdness.
>
> $ telnet www.yourserver.com 80
> GET /jed/login.php
Well, DOH! I forget about useful stuff like:
$ HEAD http://localhost/~jbaer/php/itsams/user/login.php
200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Connection: close
Date: Sun, 13 Oct 2002 04:03:47 GMT
Pragma: no-cache
Server: Apache/1.3.22 (Unix) PHP/4.1.1
Content-Type: text/html
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Client-Date: Sun, 13 Oct 2002 04:03:47 GMT
Client-Peer: 127.0.0.1:80
Set-Cookie: priapas-session=46b10a707c32564a66dda23e98b1c1e1; path=/;
domain=localhost
X-Powered-By: PHP/4.1.1
I also recalled to check the session files in /tmp. They're being created.
So, now I can't think of why Galeon or Mozilla are apparently discarding
the cookie. I just checked my local phpweblog testbed, and it sets/read
cookies OK.
So, trying to simplify things as much as possible:
<?php
session_start();
if (!ISSET($thecnt)) {
$thecnt = 1;
session_register("thecnt");
} else {
$thecnt++;
}
setcookie('burgers','fries');
?>
<html>
<body>
<hr>
<?php
echo "Count is $thecnt";
$ssid = session_id();
echo "<p>session is $ssid";
?>
<hr>
</body>
</html>
So, reloading this thing continually, I get a different session id each
time, and, obviously, $thecnt = 1. The burgers/fries cookie does get set.
Using the HEAD command, I see both Set-Cookie headers for the above
script.
????????
jed
--
We're frogs who are getting boiled in a pot full of single-character
morphemes, and we don't notice. - Larry Wall; Perl6, Apocalypse 5
More information about the clue-tech
mailing list