Jump to content

[SOLVED] SESSION being set even before its called


Nolongerused3921

Recommended Posts

For some reason when I set a $_SESSION after a mysql statement, the $_SESSION ends up being assigned before anything before it has a chance to run...
I have no idea what is going on here, all I have is an inkling... I'm afraid that ob_start() is responsible for this, and its become a major thorn in my side, and my temporary solution is causing more trouble then it is worth....

So,
a) What could be causing this, if not ob_start()
b) Regardless of the answer to (a), how can I fix this?


Example of it (This is obviously not the actual code, just pseudo code as the actual code is nearly 1000 lines long):
($_SESSION['blah'] = "blah" before being reassigned)
[code=php:0]
if ($action == this) {
$mysql->query(add the session into the database);
//Done with the session
$_SESSION['blah'] = 0;
redirect to new page();
}
[/code]

This would result in 0 being put into the query instead of "blah".
Well $_SESSION is considered a header, is it not? I'm afraid that its automatically being placed before the logic in the buffer then the php is being executed afterwards... Although I'm not sure
I just know that after placing [b]many[/b] print's, the $_SESSION is screwed up when inside the main logic ($action == "blah"), as long as another $_SESSION reassignment is in there as well... Which makes me think SESSION really is a header, and php doesn't execute code until after moving headers.
Well... To be honest I've been aware of the problem for awhile, I just need to know how to fix it, which like you said is another issue :(
If anyone has ran into this problem before I would be incredibly thankful if you'd tell me how you fixed it
$_SESSION[] is technically not a header. however since it is stored within the browser itself... php does grab them from the browser as tho it were a header. it does this before anything is returned to the browser, which is why session_start(); after text has been output dies immediatly.

simple fix is putting session_start(); before the ob_start(); that should fix it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.