Page 1 of 1

SESSION problem

Posted: Wed Jan 13, 2010 5:35 pm
by OldRod
I have something not working :(

When a user logs in, I call authenticate.php and in that file is the following code that runs if the user enters a valid username/password:

Code: Select all

$_SESSION['player_name']=$playername;
echo "<center>You are now logged in $playername. Have fun!<br></center>";
header('Refresh: 2; URL=index.php');
exit;
Over in index.php I have the following:

Code: Select all

if (isset($_SESSION['player_name']))
{
	$playername = $_SESSION['player_name'];
	echo "$playername logged in";
}
else
{
	include 'login.php';
}
So, if the session variable is set, I get a message saying I logged in. If not, I get the login boxes.

My problem is, the first branch of the if statement is not running, meaning the session is not being set (?), but I'm setting it in authenticate.php right before it refreshes back to index.php. What am I missing here? :)

Re: SESSION problem

Posted: Wed Jan 13, 2010 6:16 pm
by SpiritWebb
could the exit call in authenticate be the one killing the statement?

And in your index.php file, instead of include 'login.php'; wouldn't you want that to say, <a href='login.php'></a>?

Re: SESSION problem

Posted: Wed Jan 13, 2010 6:22 pm
by hallsofvallhalla
to test echo out the player session to see if it holds any data, if not then be sure you setting the session with session start.

Re: SESSION problem

Posted: Wed Jan 13, 2010 6:41 pm
by Chris
$_SESSION['player_name']=$_POST['playername']; ?

Re: SESSION problem

Posted: Wed Jan 13, 2010 6:47 pm
by OldRod
Ok, move along... nothing to see here...

I had been moving blocks of code around and accidentally deleted my session_start() in authenticate.php :oops:

That's why it was so puzzling - this code worked yesterday, I was just moving it around a bit :)

Re: SESSION problem

Posted: Wed Jan 13, 2010 10:42 pm
by Jackolantern
OldRod wrote:Ok, move along... nothing to see here...

I had been moving blocks of code around and accidentally deleted my session_start() in authenticate.php :oops:

That's why it was so puzzling - this code worked yesterday, I was just moving it around a bit :)
The joys of programming ;) We always look for the most complicated answer first.

Re: SESSION problem

Posted: Wed Jan 13, 2010 11:57 pm
by hallsofvallhalla
haha i had a feeling that was it.