Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd sessions 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
So let me try and convey what's happening here... it's a little awkward.

I submit a form to a script called process.php...

the top two lines of process.php are
Code:
require "defines.inc";
session_start();

Then I do some if statements which check if a certain checkbox is checked, if it is I do a
Code:
$_SESSION["my_wizard"] = $_POST;

then I echo to the browser

<script language=&quot;javascript&quot;>
top.location = &quot;[URL unfurl="true"]http://webroot/test.php&quot;;[/URL]
</script>
(Yes I'm breaking out of a frame right there... I've also tried window.location, to open test.php in the frames, same results)

Here are the entire contents of test.php
Code:
<?php
session_start();
echo &quot;<pre>&quot;;
print_r($_SESSION);
print_r($_POST);
echo &quot;</pre>&quot;;
?>

So, I submit my form, and I get taken to test.php, and I see
Array
(
)
Array
(
)

Odd, no?

Ok, so then I hit the back button, hit the frame navigation button that lets me re-fill out the form, click submit, and I get my session array appropriately populated.

Additionally, I've printed out the $_SESSION array instead of redirecting the page, and it is appropriately filled. It just seems the redirect blows away the session the first time and the first time only.

I'm assuming it's something with the redirect, though I'm not really sure. (Going to attempt some Header.location and meta redirects now)

Thanks for any help you may be able to offer,
Rob

PHP 4.3.1
Apache 2.0
Windows XP Pro
 
meta redirects are identical... totally stumped.

-Rob
 
$_POST's being empty is expected. You haven't submitted a form, so there should be no data there.

Can you verify that the information from $_POST is being correctly added to $_SESSION? Probably the easiest way it so get into the directory where PHP writes its session variable stores and inspect the file. Want the best answers? Ask the best questions: TANSTAAFL!
 
Yeah, $_POST is empty as expected, was just a notion I had that maybe something was messing up because I didn't get &quot;off&quot; the page with the $_POST data.

Anyway, I've verified it's added to session by calling a
print_r($_SESSION);
just before the redirect, and it looks correct...

Watching the directory, here's what happens...

I load the form, an empty session file is created.
I submit the form, that file gets some meat to it (The properly formatted POST data upon inspection)
Another empty session file is created

Then when I start using the back button and such, it's that second file which gets added to and everything is fine. So apparently, something is happening such that PHP considers it a new session, any idea what would cause this? The session persists through several pages after this (Obviouslly it normally goes to something more complex than that test.php) so I don't imagine it's a simple matter of expiring.

-Rob
 
To further my confusion, I removed the session_start() call which loads as the form loads originally (it's used for other session things which I don't deal with with this particular flow) and I had the same behavior, except the two files were created quickly and together, the first with the information, the second one being used with no information.

-Rob
 
Yes, I have them set to start automatically.

And the behavior above is in IE 6.0 (seeing as that's where this page needs to work for this company), but at that question I just tried Mozilla 1.3, for which I get the blank sessions, but the back button trick doesn't work. (Oddly the back button behavior is totally different, it loads up the form rather than a cannot display page from the process.php, which then requires me to use the navigational link in the frames to get to the form)

-Rob
 
gah, my mistake, I don't know what I thought you were asking... session.auto_start is set to 0.

-Rob
 
So, I've found the problem, but not the fix. It's the frames. If I skip the frames and just load up the main page, all is great. If I poke around my page loading other session_start()'s along the way, everything is great. So I guess PHP considers each frame a different page or some such? I'm not positive, but I know I've been wanting to trash the frames for some time and now I finally have a reason good enough to be accepted by everyone.

-Rob
 
I've actually encountered this. Yes, you have to use Session_start() in each frame to keep the session from getting all weird.
 
darn I found the fast solution, frames are still here to stay... if you just call it in your main frame setting document it works fine, it's setting it inside the frames themselves that get screwy. Fortunately, you can call it in the main frame setting document AND in the others without inducing problems.

So I guess the behavior is very predictable once figured out. I love the difference between mozilla and IE here btw.

Thanks for helping me get through it.

-Rob
 
So this worked, in IE and Mozilla, for about a half hour... now it's back to crapping out.

I'm baffled, I want to trash the frames anyway, but I hate having my hand forced like this.

-Rob
 
Ok, sleipnir, I'm not giving up just yet.

Printing out the session id's shows exactly what one would expect.

in i.e.
it starts as value A
then after the process becomes value B
then after using the back button stays as value B

in mozilla
it alternates back and forth between A and B

-Rob
 
The session ids themselves should stay the same. When session_start() is invoked, if a session cookie has already been passed by the browser, PHP will reuse the id number. Only if no session id has been been passed will PHP generate a new session id. Want the best answers? Ask the best questions: TANSTAAFL!
 
exactly, but they're not staying the same...

think I may have tracked it down... modifying code now.

-Rob
 
Yep that does it...

Being as this is within frames I was missing some of the links...

it was an issue of domain name, apparently some of the links I went along were in the

format
and others were in the

format

switching between this two instantiated new sessions.

I'm still baffled as to why things would work for 20 minutes before breaking again, but cest le vie (and add your own apostrophe's in the appropriate places).

Thanks for helping me get through this.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top