Page 1 of 1

PHP SESSION[HELP NEEDED]

Posted: Sat Sep 15, 2007 3:58 pm
by canishk
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:

Code: Select all

session_start();
         $_SESSION['$uid']=$u;

page 2:

Code:

Code: Select all

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

Posted: Sat Sep 15, 2007 4:05 pm
by feyd
The error you have received is posted about several times a week. Did you search for "headers already sent"?

Posted: Sat Sep 15, 2007 11:39 pm
by fly135
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


first so sorry for my poor english,i'm a chinese.

the "session_start" should be header of php file,and there is not any html out in front of these words.
such as

Code: Select all

<?php session_start();
$_SESSION['ff']="uuuuuuu";?><html><body>
<?php echo($_SESSION['ff']);</body></html>
?>
and this is error

Code: Select all

<html><body>
<?php session_start();
$_SESSION['ff']="uuuuuuu";
echo($_SESSION['ff']);</body></html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Sep 16, 2007 1:36 am
by joncampbell
you might not wanna start the session again, you might wanna do an if check to see if there is already an open session and then it should work.

something like this:

Code: Select all

if empty($_SESSION) {
         session_start();
}
also you don't wanna put $'s in your session variables, you would set a session variable with this syntax:

Code: Select all

$_SESSION['str'] = 'string';

and

$cat = $_SESSION['cat'];

The headers already being sent is probably because you are getting a warning from the second session start that there is already a current session.

Hopefully this helps.

Posted: Sun Sep 16, 2007 7:48 am
by superdezign
joncampbell wrote:The headers already being sent is probably because you are getting a warning from the second session start that there is already a current session.
Headers are automatically *sent* after ANY output has been made. An active session does not send headers.