Hi,
I am having a problem with getting some PHP code to work...
This is what I'm trying to do:
I am attempting to create my own simple login script, and so far it works properly for comparing Username and Password values to the DB and returning whether the user is correctly logging in or not(correct username & password).
In my script for checking the username & password to the DB (checklogin.php), I am trying to set up Session variables(loggedin and userid):
$myusername is a username variable that was stored from the $_POST['username'] when the script was called. Note that this $myusername variable worked for when I checked in the database, so it should store that variables value into $_SESSION['userid'] yes?
The problem at hand here is that I want my header(header.php) to check if the user is logged in and IF SO then change the link 'Login' to a link titled with their username.
*Example:*
When NOT logged in, this is the menu:
<a href="">Home</a> | <a href="">About</a> | <a href="">Login</a>
When they ARE logged in, this is the menu(using username Jeeter):
<a href="">Home</a> | <a href="">About</a> | <a href="">Jeeter</a>
*End of Example*
This is the code in my header (header.php) file that checks if the user is logged in, and if they are, attempts to build a hyperlink using their name:
When I attempt to use this scripting and all the files together I get a successful login check, and a successful redirect. And it IS able to check the $_SESSION['loggedin'] to get 0 or 1 to determine the user being logged in or not...but when it goes to create the hyperlink I get this:
<a href="user.php">Panel</a>
...But it should be:
<a href="user.php">Jeeter Panel</a>
Any help is very appreciated!! If you need anymore information to determine what is is that I need, just drop a reply.
Thank you,
jeeter
I am having a problem with getting some PHP code to work...
This is what I'm trying to do:
I am attempting to create my own simple login script, and so far it works properly for comparing Username and Password values to the DB and returning whether the user is correctly logging in or not(correct username & password).
In my script for checking the username & password to the DB (checklogin.php), I am trying to set up Session variables(loggedin and userid):
PHP:
//Set loggedin to 1 meaning user is CURRENTLY LOGGED IN.
$_SESSION['loggedin'] = 1;
//Set session userid to the username used. Stored in $myusername
$_SESSION['userid'] = $myusername;
//Redirect to index, now logged in
header(location:index.php);
The problem at hand here is that I want my header(header.php) to check if the user is logged in and IF SO then change the link 'Login' to a link titled with their username.
*Example:*
When NOT logged in, this is the menu:
<a href="">Home</a> | <a href="">About</a> | <a href="">Login</a>
When they ARE logged in, this is the menu(using username Jeeter):
<a href="">Home</a> | <a href="">About</a> | <a href="">Jeeter</a>
*End of Example*
This is the code in my header (header.php) file that checks if the user is logged in, and if they are, attempts to build a hyperlink using their name:
PHP:
//See if user is already logged in
if ($_SESSION['loggedin'] = 1) //Logged in
{
//Store sessions userid into $name variable
$name = $_SESSION['userid'];
//TODO: have username show in hyperlink..
//Create hyperlink using $name variable
echo "<td><a href=\"user.php\">{$name} Panel</a></td>";
}
else //Not Logged in
{
echo "<td><a href='login.php'>Login</a></td>";
}
<a href="user.php">Panel</a>
...But it should be:
<a href="user.php">Jeeter Panel</a>
Any help is very appreciated!! If you need anymore information to determine what is is that I need, just drop a reply.
Thank you,
jeeter