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".
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

$_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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.