PHP 5.2 Sessions
Moderator: General Moderators
PHP 5.2 Sessions
Has anyone gotten PHP 5.2 and Apache 2.2 on Windows XP SP2 working with sessions? This is far from my first post about this, and I have been searching for days, as well as attempting various configurations, all to no avail. If anyone else has gotten sessions working with these versions, please post here how you did it. I've had one person on another forum post that he just followed instructions, which is what I did in the first place, but sessions are still not working on my localhost. I can see session files being created, but session data is simply not being passed from one page to the next, and instead a new session file is created for every new page. I understand that PHP 5.2 handles sessions a little differently, in terms of GC in particular, but I still don't see that I've configured it wrong.
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
Firefox has an extension called HttpLiveHeaders that will show the request header. But you can just run the following script (in a context that is expecting the session cookie) and post its output here.
Code: Select all
print_r($_COOKIE);Thanks. What I got was Array(), which, since print_r prints the array struct, means it's empty. I changed php.ini to use, not use, scramble, bake, and deep-fry cookies, all with the same result. Firefox (I have 2) is set to use cookies and my firewall allows all cookies.
Are you using Apache 2.2.3 or an older version? Sometimes there are compatibility issues with the absolute latest of PHP and Apache. Maybe I just have a version combo that hasn't been patched yet.
Interestingly enough, I downloaded the PHP 5.2 .msi and tried an automatic installation - same result. So maybe it *is* an incompatible version.
Are you using Apache 2.2.3 or an older version? Sometimes there are compatibility issues with the absolute latest of PHP and Apache. Maybe I just have a version combo that hasn't been patched yet.
Interestingly enough, I downloaded the PHP 5.2 .msi and tried an automatic installation - same result. So maybe it *is* an incompatible version.
D'oh!
Here's the real header output. First from the test page where I set the session var, the second from the linked page that attempts to call that session var. Seems like cookies are just not part of the picture here.
http://localhost/dev/studio5/admin/test.php
GET /dev/studio5/admin/test.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
Date: Sun, 10 Dec 2006 18:14:56 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Transfer-Encoding: chunked
----------------------------------------------------------
http://localhost/dev/studio5/admin/test2.php
GET /dev/studio5/admin/test2.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/dev/studio5/admin/test.php
HTTP/1.x 200 OK
Date: Sun, 10 Dec 2006 18:14:58 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.0
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html
Transfer-Encoding: chunked
----------------------------------------------------------
Here's the real header output. First from the test page where I set the session var, the second from the linked page that attempts to call that session var. Seems like cookies are just not part of the picture here.
http://localhost/dev/studio5/admin/test.php
GET /dev/studio5/admin/test.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
Date: Sun, 10 Dec 2006 18:14:56 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Transfer-Encoding: chunked
----------------------------------------------------------
http://localhost/dev/studio5/admin/test2.php
GET /dev/studio5/admin/test2.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/dev/studio5/admin/test.php
HTTP/1.x 200 OK
Date: Sun, 10 Dec 2006 18:14:58 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.0
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html
Transfer-Encoding: chunked
----------------------------------------------------------
Yep. I can't even get this dirt-simple test to work:
test.php:
test2.php:
The last time I installed PHP, I selected install as Apache 2.2 module and otherwise left all the defaults.
test.php:
Code: Select all
<?
session_start();
$_SESSION["user_id"]=23;
?>
<a href="test2.php">go</a>Code: Select all
<?
session_start();
echo $_SESSION["user_id"];
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>Results:
PHP Version: 5.2.0
PHP OS: WINNT
Error Reporting: 6143 (E_ALL)
Register Globals: Off
Short Tags: Off
Display Errors: On
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
bcmath calendar com_dotnet ctype
session filter ftp hash
iconv json odbc pcre
Reflection date libxml standard
tokenizer zlib SimpleXML dom
SPL wddx xml xmlreader
xmlwriter apache2handler
PHP Version: 5.2.0
PHP OS: WINNT
Error Reporting: 6143 (E_ALL)
Register Globals: Off
Short Tags: Off
Display Errors: On
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
bcmath calendar com_dotnet ctype
session filter ftp hash
iconv json odbc pcre
Reflection date libxml standard
tokenizer zlib SimpleXML dom
SPL wddx xml xmlreader
xmlwriter apache2handler