I have a website where users can log in. I have tried:
and When users login I set their session as
Did you start the session before using it?
So to set it:
And to retrieve it on another page do:
EDIT
Some more information about how to create a loginform.. You say you tried setting $_SESSION['user']
but that this didn't work.
So just make sure that you actually did a session_start();
before that. If you did, everything should work. Unless you assign an empty variable to the session. So doublecheck that the variable you assign actually contains a value. Like:
In the tutorial you linked me to they are doing:
$_SESSION[user]=$_GET[userlogin];
This means they are assigning a value they got from their loginform that they create here:
function loginform() {
print "please enter your login information to proceed with our site";
print ("username password
");
print "";
print "register now!
";
}
There you see . But there is no
tag around this form.. So this won't properly post. So what you should do is the following:
This form will post the form back to index.php with userlogin and password as $_POST
variables.
In your index.php you can then do:
I can't make it much clearer without writing the entire code for you. So I hope this helps you.