SESSION problem

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

SESSION problem

Post 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? :)
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: SESSION problem

Post 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>?
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: SESSION problem

Post 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.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: SESSION problem

Post by Chris »

$_SESSION['player_name']=$_POST['playername']; ?
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: SESSION problem

Post 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 :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: SESSION problem

Post 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.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: SESSION problem

Post by hallsofvallhalla »

haha i had a feeling that was it.
Post Reply

Return to “Advanced Help and Support”