Re: sessions failing to persist
| From: | Michael R. Wayne | Date: | Mon, 03 May 2004 15:50:26 +0000 |
| Subject: | Re: sessions failing to persist | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185194@lists.php.net to get a copy of this message | ||
On Mon, May 03, 2004 at 09:42:14AM +0200, Richard Harb wrote:
> Well, the cookie won't ever be set in his configuration...
Correct.
> In the html source of the rendered page, is the form action modified
> to reflect the current session id (to post it as a $_GET value)? or:
> does the <input type="hidden" value reflect a valid session id?
Using the suggestions below, I changed to a GET and the session ID
is showing up in the logs. If I leave in the hidden field, I see it
twice (as I would expect):
"GET
/g/xxx.php?PHPSESSID=785627781f2cb4674f06a79788925c1e&field=bar&PHPSESSID=785627781f2cb4674f06a79788925c1e
HTTP/1.1"
so, I removed that to get:
"GET /g/xxx.php?PHPSESSID=785627781f2cb4674f06a79788925c1e&field=bar HTTP/1.1"
Note that when I use GET, the session ID is getting set on the
second call. So I see:
Log shows: "GET /g/xxx.php HTTP/1.1"
Browser shows:
Stage:0 SessionID: 52a504d36a834ea747793d3fb61908ca
___ Submit
Stage:1 SessionID: 52a504d36a834ea747793d3fb61908ca Request: Array ( )
foo<hit submit>
Log shows: "GET /g/xxx.php?PHPSESSID=52a504d36a834ea747793d3fb61908ca&field=foo
HTTP/1.1"
Browser shows:
# Note on the following line that the sessionID was not preserved
Stage:0 SessionID: 06d6ff28592b54f42dfb7cef6a56780e
___ Submit
Stage:1 SessionID: 06d6ff28592b54f42dfb7cef6a56780e Request: Array ( [PHPSESSID] =>
52a504d36a834ea747793d3fb61908ca [field] => foo )
bar<hit submit>
# Second time it's called, it seems to persist (only with GET, not with POST)
Log shows: "GET /g/xxx.php?PHPSESSID=06d6ff28592b54f42dfb7cef6a56780e&field=bar
HTTP/1.1"
Browser shows:
Stage:1 SessionID: 06d6ff28592b54f42dfb7cef6a56780e
___ Submit
Stage:1 SessionID: 06d6ff28592b54f42dfb7cef6a56780e Request: Array ( [PHPSESSID] =>
52a504d36a834ea747793d3fb61908ca [field] => foo )
A file is being created in the sesion directory with a name which
matches the session ID shown in the logs and that file contains
stage|i:1;
> If any or all those values (session id) are present in the source: do
> they get posted?
> A print_r($_REQUEST) should shed some light on that...
Yes, see above.
> You also could change the form method from "post" to "get" for
> debugging purposes, so you can see on one glance what variables are
> assigned and which values they have.
Done, as I suspected the values are being set in the browser and are
being passed to the server.
> another poster mentionned whether the session dir is writeable...
Yup.
Current code:
<?
if (!isset($_SESSION["stage"])) {
$_SESSION["stage"] = 0;
}
if (!isset($_POST["field"])) { $_POST["field"] = ""; }
?>
<html>
<head><title>PHP Test page</title></head>
<body>
<?
echo "Stage:"; echo $_SESSION["stage"];
echo " SessionID: "; echo session_id();
$_SESSION["stage"] = 1;
?>
<form method="post" action="xxx.php">
<input type="text" maxlength="7" size="7"
name="field" value="<?echo $_POST["field"]?>">
<input type="submit" value="Submit">
</form>
<?
echo "Stage:"; echo $_SESSION["stage"]; echo " ";
echo " SessionID: "; echo session_id(); echo " ";
echo " Request: "; print_r($_REQUEST);
?>
</body> </html>