473,386 Members | 1,752 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,386 software developers and data experts.

Disappearing $_SESSION

I have created a wizard which walks a user through a process of
selecting data to be generated into an XML file.

Each page adds its own data to $_SESSION, until the final page. On this
page, an input button launches a PHP script (genHTML.php) that creates
an HTML file. The genHTML file starts by setting two headers:

header('Content-type: text/html');
header('Content-Disposition: attachment; filename="countymap.html"');

The first time I create the HTML file (which is actually a Smarty
template), the variable $_SESSION['key'] is added to the countymap.html
template and the user is prompted to save the countymap.html file.

However, if I click the button to generate the file more than once,
$_SESSION['key'] is somehow unset.

Each page of the wizard calls session_write_close() at the end of the
script, which I thought would solve the problem, but did not.

Can anyone assist me?

Jason

Oct 11 '05 #1
7 1860
Jason,
I have created a wizard which walks a user through a process of
selecting data to be generated into an XML file.

Each page adds its own data to $_SESSION, until the final page. On this
page, an input button launches a PHP script (genHTML.php) that creates
an HTML file. The genHTML file starts by setting two headers:

header('Content-type: text/html');
header('Content-Disposition: attachment; filename="countymap.html"');

The first time I create the HTML file (which is actually a Smarty
template), the variable $_SESSION['key'] is added to the countymap.html
template and the user is prompted to save the countymap.html file.

However, if I click the button to generate the file more than once,
$_SESSION['key'] is somehow unset.

Each page of the wizard calls session_write_close() at the end of the
script, which I thought would solve the problem, but did not.


Do all pages have session_start at the top of them, including the page
where you are generating the file?

Are you closing the session or setting the session to an array on the
page which generates the file?

What makes me as this is you said the genHTML file starts by setting two
headers, you MUST have the session_start at the beginning!

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 12 '05 #2
Mike,

All pages have session_start() immediately following the includes. The
headers are set AFTER the session_start().

Following the session_start() is a mess of print() functions that
output a formatted XML file. I just realized that this file doesn't end
with session_write_close(). Is this causing the problem?

Jason

Oct 12 '05 #3
DartmanX wrote:
Mike,

All pages have session_start() immediately following the includes. The
headers are set AFTER the session_start().

Following the session_start() is a mess of print() functions that
output a formatted XML file. I just realized that this file doesn't end
with session_write_close(). Is this causing the problem?

Jason


Jason,

Is there *anything* in the include files which could cause output to be
sent? i.e a blank line?

Try putting

<?php session_start(); ?>

as the very first line in your pages (before ANYTHING else - even a
blank line!). See if that works.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 12 '05 #4
There doesn't seem to be anything causing any output (the two includes
are PEAR::DB and Smarty). Moving the session_start() to the very top
had no effect, the Session variable in question still disappeared.

I'm still stumped.

Oct 12 '05 #5
DartmanX wrote:
There doesn't seem to be anything causing any output (the two includes
are PEAR::DB and Smarty). Moving the session_start() to the very top
had no effect, the Session variable in question still disappeared.

I'm still stumped.


With that being said the session is getting reset somewhere in the
script. If you follow your click path you will be sure to find most
likely an incorrect variable assignment or something rather odd with how
the session is being set.

Sessions don't just disappear :)

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 13 '05 #6
DartmanX wrote:
<snip>
I just realized that this file doesn't end
with session_write_close(). Is this causing the problem?


FWIW, there is no need to add session_write_close() at the end of
the file, as it is implicitly done. session_write_close() has to be
used when you just want to close the session handle in the middle.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Oct 13 '05 #7
I was calling that explicitly to try to solve the problem.

I think I fixed the bug by moving the logic that set the disappearing
$_SESSION to a page that did not use header().

Jason

Oct 14 '05 #8

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

Similar topics

0
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its...
21
by: axlq | last post by:
Someone please tell me if I've discovered a PHP bug. I'm sitting in front of several computers on my home network, behind a NAT firewall/router. I am testing my web site on these different...
12
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if...
0
jeremydowe
by: jeremydowe | last post by:
Hi I have a problem with Session Id data disappearing between php pages? What is going wrong after I start the session and begin with the $_SESSION? Do I need to use session_write_close() ? ...
2
by: somecrazyguy | last post by:
Take the following code, one would think that there was absolutely no link between $test and $_SESSION. But if you reload the page, guess what... "After=FAILED". Why? Because for some reason,...
4
by: Pseudonyme | last post by:
Dear Sirs and Madams, Receive as information that storing a MYSQL result under $_SESSION was accelerating web page displays processes ? Absolutly needed but impossible to get this working ! I...
2
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session...
24
by: Pink Pig | last post by:
I'm trying to track down an annoying problem that only occurs when I access my pages on a remote server using IE6. If I run instead run from localhost, IE6 works fine, and if I use another browser...
3
by: JRough | last post by:
I want to save two variables in a $_SESSION for use in another page: $_SESSION = $mark; $_SESSION = $num; then on the other page I did this to get the value: $mark =$_SESSION; $num =...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.