473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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-

Feb 25 '06 #1
5 1152
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
Feb 25 '06 #2
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-

Feb 25 '06 #3
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
Feb 26 '06 #4
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-

Feb 26 '06 #5
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-

Feb 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Werner | last post by:
Hi Patrick! Can you give an example of how to use a frameset inside an aspx-file? When I create a new frameset in Visual Studio.Net it just gives me a htm-File. Or give me a link where I can...
1
by: RUSSELL MCGINNIS | last post by:
I have a web site that uses Form Authentication with the Session timeout set to 20 minutes, however one of the pages refreshes itself every 30 seconds. Is there a way to override the session...
4
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
4
by: Aidas Pasilis | last post by:
I'm saving some values to the Session state and get some strange results. To be short I'll write example code and standart behavior: Code Example:...
3
by: serge calderara | last post by:
Dear all I have a strange behaviour using session. ON my form load when the page is first display I create a session variable to stor connection objects as follow : If not IsPostBack then...
15
by: John Howie | last post by:
I've found very unusual behavious when using sessions on two different servers. I'm using sessions to handle simple log in. When the form submits the values are checked against a MySQL table. If...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
6
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi Our application was using Session variables to store business object for our Web Forms successfully until someone opened a cloned IE window using Control-N key press. The cloned window...
11
Dormilich
by: Dormilich | last post by:
recently I encounter a very strange behaviour of the session variable. if the cookies are disabled, the session id is totally misplaced (see code). instead being attached to the URL it is placed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.