473,224 Members | 1,464 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,224 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 1850
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.