Jump to content

PHP SESSION[HELP NEEDED]


canishk

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

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.