The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
I'm just wondering, how do I get this whole "login" thing nailed properly? And I mean, I want it to
1. Check username and password against the database
2. If the user is there and his/her password is correct, login to next screen
3. Keep user logged in.
I've been reading up on sessions or something, I'm not exactly sure on how these work however, which is why I was wondering if any of you guys could give us a hand.
Cheers.
> I'm currently just messing around with PHP, creating a login form to
> be exact (I'm having one of those 'create a template for use on
> future projects') days.
>
> I'm just wondering, how do I get this whole "login" thing
> nailed properly? And I mean, I want it to
>
> 1. Check username and password against the database
> 2. If the user is there and his/her password is correct, login to
> next screen
> 3. Keep user logged in.
>
> I've been reading up on sessions or something, I'm not exactly sure
> on how these work however, which is why I was wondering if any of you
> guys could give us a hand.
>
> Cheers.
1. Depends what you are doing with the password and what tables you have in your database.
something like .....
$user = $_POST['username'];
$password = $_POST['password'];
$password2 = md5($password);
$result = mysql_query("SELECT username FROM user WHERE username= '$user' AND password = '$password2'");
2.Something like....
if ($myrow = mysql_fetch_array($result))
{
$_SESSION['loggedin'] = true;
$_SESSION['user'] = $_POST['username'];
echo'
You have been successfully logged in
';echo'
Click here to proceed to the next page.
';}
else
{
echo'
Login Error
';
echo'
User not found. You have entered your username and/or password incorrectly. Please try again.
';$_SESSION['loggedin'] = false;
}
3.At the start of every page you wish them to be logged in to see just use.
session_start();
You MUST have this before you output anything or it dosn't work.
You can then use
$_SESSION['loggedin'] to check if someone is logged in.
For example you could have :
//check that user is logged in
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true)
{
DISPLAY THE PAGE
}
else
{
LINK them to the login page as they aren't logged in.
}
Hope this helps.
I'm just wondering, how do I get this whole "login" thing nailed properly? And I mean, I want it to
1. Check username and password against the database
2. If the user is there and his/her password is correct, login to next screen
3. Keep user logged in.
I've been reading up on sessions or something, I'm not exactly sure on how these work however, which is why I was wondering if any of you guys could give us a hand.
Cheers.