Trouble with session variables
Posted: Fri Nov 19, 2010 2:23 am
Hello,
I have a function described below;
I then direct to another page using;
And then echo the variables using;
Should be simple but as always it's not working. The only text I see is from the echo $_SESSION['validSession']; line, the rest shows as nothing as if the variables are set to null.
So, what I thought was that it must be the way I declare the variables $username and $userid but if I echo these on the page where the function is called they display correctly. Soooo... the only thing I can think could be wrong is;
These two lines. But I cannot for the life of me see why?! I'm a bit of a noob and I'm hoping it is blindingly obvious what the problem is, so could someone be so kind as to enlighten me please?
Also, are there some easy ways to make this more secure? It looks like the session can be hijacked relatively easily but other than regenerating the id I don't know what to do
Thanks
I have a function described below;
Code: Select all
function validateUser()
{
session_regenerate_id ();
$_SESSION['validSession'] = 1;
$_SESSION['useridSession'] = $userid;
$_SESSION['usernameSession'] = $username;
}
Code: Select all
header('Location: nextpage.php');
Code: Select all
echo $_SESSION['validSession'];
echo $_SESSION['useridSession'];
echo $_SESSION['usernameSession'];
So, what I thought was that it must be the way I declare the variables $username and $userid but if I echo these on the page where the function is called they display correctly. Soooo... the only thing I can think could be wrong is;
Code: Select all
$_SESSION['useridSession'] = $userid;
$_SESSION['usernameSession'] = $username;
Also, are there some easy ways to make this more secure? It looks like the session can be hijacked relatively easily but other than regenerating the id I don't know what to do
Thanks