Sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zeyber
Forum Newbie
Posts: 16
Joined: Wed Sep 26, 2007 9:23 pm

Sessions

Post by Zeyber »

I am trying to save something from the text field as a session variable. It doesnt seem to be working :(

First page has:

Code: Select all

session_start();
//Username Entered
$accuser = $_POST["name"];
$_SESSION['user']=$accuser;
Second Page has:

Code: Select all

echo $_SESSION['user'];
Nothing appears to be showing on the second page
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Sessions

Post by Christopher »

Second Page has:

Code: Select all

session_start();
echo $_SESSION['user'];
(#10850)
Zeyber
Forum Newbie
Posts: 16
Joined: Wed Sep 26, 2007 9:23 pm

Post by Zeyber »

Now I get an error:


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/www/???/logindone.php:10) in /home/www/???/logindone.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/???/loginpassdone.php:10) in /home/www/???/loginpassdone.php on line 11

This is how it goes anyway:

login.php (text field)
(First page) logindone.php (session)
loginpass.php (text field)
(Second page) loginpassdone.php (session)
Last edited by Zeyber on Thu Sep 27, 2007 5:02 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Search high and low for the phrase "headers already sent". It's a popular theme.
Zeyber
Forum Newbie
Posts: 16
Joined: Wed Sep 26, 2007 9:23 pm

Post by Zeyber »

I don't quite see how that helps :(
shylor
Forum Newbie
Posts: 13
Joined: Thu Sep 27, 2007 12:52 pm

Post by shylor »

When the header function is sent twice that error will happen. So you might have this line in your main file and in another file that is included to the first file.

Code: Select all

header()
and with sessions starts, they must always be on the top of the page at hand. you must open the php page and start the session. sessions starts must be on every page too! if you have a config.inc.php they might not be needed if its always included into another file.
Zeyber
Forum Newbie
Posts: 16
Joined: Wed Sep 26, 2007 9:23 pm

Post by Zeyber »

It worked! Thanks so much! You have led a little spirited soul towards the light!
shylor
Forum Newbie
Posts: 13
Joined: Thu Sep 27, 2007 12:52 pm

Post by shylor »

No problem, glad to help!
Post Reply