canishk Posted September 15, 2007 Share Posted September 15, 2007 I am trying to implement session variables in my new php project. I would like to know can i set and get variables in session... my current program contains: page 1: Code: session_start(); $_SESSION['$uid']=$u; page 2: Code: session_start(); $u=$_SESSION['$uid']; echo("$u"); but i got this warning with the result.. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent how can i solve this?? please help Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 The session seems to have already been started, therefore it maybe set to start automatically in php.ini, therefore you don't need to call 'session_start();'. Also you won't be able to use newly set session variables until the page has changed... that sounds strange but try it... Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2007 Share Posted September 15, 2007 Where is that snippet of code? session_start() should not be used after ANY output to the browser, this includes html or stray spaces like so: <?php session_start(); ?> OR <p>hello</p> <?php session_start(); ?> ^ Those will cause that error. as for rarebit saying newly set session variables aren't accessible until after the next page load: I don't think that's right. It's true for cookie variables, I can say for sure. But can someone else confirm it's the same for sessions? Or can you (rarebit) provide quotation from the documentation where it says so? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 Try it! It's from a book i've got, i've not lloked for it in the php docs but enough people complain about the error on here... please prove it wrong... i'll go try it now, cos I agree it doesn't make sense as to why, other than it's stored by the server not the interpreter? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 You could be right actually! Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 15, 2007 Share Posted September 15, 2007 you can access a session variable on the same page you set it. Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 SAMS Teach Yourself PHP, MySQL and Apache, ISBN 0-672-32620-5, pages 205/6 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.