I have a website where users can log in. I have tried:
<?php echo $_SESSION ['userlogin']
and When users login I set their session as userlogin, but it won't show their username.
This is the tutorial I used
I have a website where users can log in. I have tried:
<?php echo $_SESSION ['userlogin']
and When users login I set their session as userlogin, but it won't show their username.
This is the tutorial I used
Without showing more code we cant comment much, but are you sure you are calling session_start in each page you use your session variable too? Also ensure you are using the same capitalisation (userlogin != UserLogin).
Put session_start(); before the echo
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:
This means they are assigning a value they got from their loginform that they create here:
There you see
<input type='text' name='userlogin' size'20'>
. But there is no<form></form>
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.