Nolongerused3921 Posted January 18, 2007 Share Posted January 18, 2007 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 https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/ Share on other sites More sharing options...
trq Posted January 18, 2007 Share Posted January 18, 2007 ob_start effects output, not script logic. Its does seem odd though. Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163628 Share on other sites More sharing options...
Nolongerused3921 Posted January 18, 2007 Author Share Posted January 18, 2007 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 sureI 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 https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163629 Share on other sites More sharing options...
trq Posted January 18, 2007 Share Posted January 18, 2007 Yeah that makes sense. Sessions need cookies, and cookies are created via header calls.Id'e say youv'e found the problem, fixing it is probably all together another issue. Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163636 Share on other sites More sharing options...
Nolongerused3921 Posted January 18, 2007 Author Share Posted January 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163639 Share on other sites More sharing options...
taith Posted January 18, 2007 Share Posted January 18, 2007 $_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 https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163641 Share on other sites More sharing options...
Nolongerused3921 Posted January 18, 2007 Author Share Posted January 18, 2007 That fixed it! Thanks, the bug has annoyed me to no extent for the past 2 weeks, I just never put any real thought into it until now.Edit: Wheres "topic solved"...? Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163648 Share on other sites More sharing options...
taith Posted January 18, 2007 Share Posted January 18, 2007 welcomebottom left corner :-) Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163651 Share on other sites More sharing options...
trq Posted January 18, 2007 Share Posted January 18, 2007 Sorry, the board has been upgraded and the topic solved mod is no longer with us. Will be fixed soon.Ive edited your title. Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163652 Share on other sites More sharing options...
Nolongerused3921 Posted January 18, 2007 Author Share Posted January 18, 2007 Okay thanks, I was worried there since it wasn't showing up for me. Link to comment https://forums.phpfreaks.com/topic/34725-solved-session-being-set-even-before-its-called/#findComment-163654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.