(the following has also been posted on the sitepoint forums, so if interested you may want to review the thread there before responding:
http://www.sitepointforums.com/showthread.php?s=&threadid=37028)
I was having a problem getting somes scripts that use sessions to pass the session variables along. They worked fine on my local machine (running Apache) but not when I upload them to the hosting company running Apache. The ISP is running PHP 4.0.6, BTW.
Therefore, I devised the following simple test script. Here's page one:
<?
session_start();
session_register("test_var");
$test_var = "Testing 1-2-3...";
?>
<A HREF="page2.php">Next Page</A>
Here's page two
<?
session_start();
print "the content of \$test_var is $test_var<BR>";
$count = count($HTTP_SESSION_VARS);
print "the count of elements in \$HTTP_SESSION_VARS is $count";
print "<BR>the session id is: " . $PHPSESSID;
print "<BR>" . $HTTP_SESSION_VARS['test_var'] ;
?>
Here's the weird part:
When I run these scripts, I can see the session id stored in $PHPSESSID, but the count of elements for $HTTP_SESSION_VARS is 0, and the variable $test_var is empty.
When the hosting company A runs the scripts on their computer, even dialing out through an outside ISP (i.e. not viewing them internally), they see everything as it should display.
However, when I load the scripts on hosting company B's computer the scripts process fine!
Unless I'm really overlooking something obvious, I think the scripts are constructed OK.
It seems like it can't be hosting company A, since when they view the scripts they process OK and produce correct output.
It can't be that sessions aren't working, because the session id is set (and when I FTP into the hosting company and view the /tmp directory I see a session id matching the number that displays on my screen).
It can't be my browser or machine, since when I view them on hosting company B's site they show up fine (also I've tested on two different machines, using W98 and W2K, using IE5.0 IE5.5 and NS4.7).
So what in the sam hill is it? The session id is passing, but the $HTTP_SESSION_VARS is empty.
Could it be a problem with the php.ini on the hosts' machine? (To me, untutored soul that I am, their ini looks normal, you can view the php settings of hosting company A by going to this link I've thrown up: http://www.flexiss.net/phpinfo.php.
Another clue: when I run my test scripts and then view the /tmp directory on the server, I see that a new session file is indeed created there, however it is 0 bytes. When the hosting company tests the scripts, a session file is created but has the variable in it. Therefore: when I run the script it does create a session, but fails to write any data to the file.
The hosting company has been working on this for days but without a solution. Any takers out there?
Thanks in advance,
Ross Barefoot
http://www.flexiss.net