Confusing session behaviour

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-25-2006
David Haynes
 
Posts: n/a
Default Confusing session behaviour

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-

Reply With Quote
  #2 (permalink)  
Old 02-25-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: Confusing session behaviour

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


Reply With Quote
  #3 (permalink)  
Old 02-25-2006
David Haynes
 
Posts: n/a
Default Re: Confusing session behaviour

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-

Reply With Quote
  #4 (permalink)  
Old 02-26-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: Confusing session behaviour

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


Reply With Quote
  #5 (permalink)  
Old 02-26-2006
David Haynes
 
Posts: n/a
Default Re: Confusing session behaviour

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-

Reply With Quote
  #6 (permalink)  
Old 02-26-2006
David Haynes
 
Posts: n/a
Default Re: Confusing session behaviour

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-

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0