This is a discussion on Confusing session behaviour within the PHP Language forums, part of the PHP Programming Forums category; I am running Apache 2, PHP 5.0.5, and windows XP I have one php file that populates a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am running Apache 2, PHP 5.0.5, and windows XP
I have one php file that populates a SESSION variable and another that consumes it. If I call the first one from the URL line of the browser, the form fills correctly (i.e. the values are passed in the session) If I call the first program from the second via an <a href> the session is lost. So, from the browser URL, the order would be: [first.php] session_start(); $_SESSION['foo'] = $foo; session_write_close(); header("location: second.php"); exit; [second.php] session_start(); $foo = $_SESSION['foo']; print_r($foo); This works. If I change second.php to be: session_start(); $foo = $_SESSION['foo']; <a href="first.php">first</a> then the session is empty when the href is selected. What am I missing? -david- |
|
|||
|
David Haynes wrote:
> If I call the first program from the second via an <a href> the > session is lost. > > So, from the browser URL, the order would be: > [first.php] > session_start(); > $_SESSION['foo'] = $foo; > Where is $foo initially defined? JW |
|
|||
|
Janwillem Borleffs wrote:
> David Haynes wrote: >> If I call the first program from the second via an <a href> the >> session is lost. >> >> So, from the browser URL, the order would be: >> [first.php] >> session_start(); >> $_SESSION['foo'] = $foo; >> > > Where is $foo initially defined? > > > JW > > $foo just represents some meaningful data. I have a real minimal example now: [file: foo.ctrl.php] <?php session_start(); $foo[] = array('this'=>1, 'that'=>2); $_SESSION['foo'] = $foo; session_write_close(); header('location: foo.php'); exit; ?> [file: foo.php] <?php session_start(); printf("_SESSION<br>\n"); $foo = $_SESSION['foo']; print_r($foo); echo <<<EOF <html> <head></head> <body> <br/> <a href="foo.ctrl.php>foo</a> </body> EOF; ?> Calling foo.ctrl.php from the browser URL produces: _SESSION Array ( [0] => Array ( [this] => 1 [that] => 2 ) ) foo clicking on the 'foo' link produces: _SESSION foo -david- |
|
|||
|
David Haynes wrote:
> Calling foo.ctrl.php from the browser URL produces: > _SESSION > Array ( [0] => Array ( [this] => 1 [that] => 2 ) ) > foo > > clicking on the 'foo' link produces: > _SESSION > Beside that the assignment $foo[] = ... causes foo to be populated with another array, this works on my environment as expected. Make sure that the session.cookie_path directive in your ini file is set to "/"; also try to set the session.use_trans_sid directive in the same file to "1", which should cause the session id to be appended to the link when there are problems setting the cookie. JW |
|
|||
|
Janwillem Borleffs wrote:
> David Haynes wrote: >> Calling foo.ctrl.php from the browser URL produces: >> _SESSION >> Array ( [0] => Array ( [this] => 1 [that] => 2 ) ) >> foo >> >> clicking on the 'foo' link produces: >> _SESSION >> > > Beside that the assignment $foo[] = ... causes foo to be populated with > another array, this works on my environment as expected. > > Make sure that the session.cookie_path directive in your ini file is set to > "/"; also try to set the session.use_trans_sid directive in the same file to > "1", which should cause the session id to be appended to the link when there > are problems setting the cookie. > > > JW > > Thanks for the suggestions JW. Unfortunately, they did not fix my problem. Maybe its a windows or php 5.0.5. thing? I'll move the example to Linux and see what happens. -david- |
|
|||
|
David Haynes wrote:
> Janwillem Borleffs wrote: >> David Haynes wrote: >>> Calling foo.ctrl.php from the browser URL produces: >>> _SESSION >>> Array ( [0] => Array ( [this] => 1 [that] => 2 ) ) >>> foo >>> >>> clicking on the 'foo' link produces: >>> _SESSION >>> >> >> Beside that the assignment $foo[] = ... causes foo to be populated >> with another array, this works on my environment as expected. >> >> Make sure that the session.cookie_path directive in your ini file is >> set to "/"; also try to set the session.use_trans_sid directive in the >> same file to "1", which should cause the session id to be appended to >> the link when there are problems setting the cookie. >> >> >> JW >> > Thanks for the suggestions JW. > > Unfortunately, they did not fix my problem. Maybe its a windows or php > 5.0.5. thing? > > I'll move the example to Linux and see what happens. > > -david- > It turns out to be firewall-related. When I disabled my (local) firewall, the application worked as I expected. Thanks for all the suggestions folks. -david- |