GetDotted Domains

Viewing Thread:
"PHP/MySQL question"

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.

Sat 15/01/05 at 16:35
Regular
Posts: 10,364
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.
Sat 15/01/05 at 16:52
Regular
"Picking a winner!"
Posts: 8,502
gamesfreak wrote:
> 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.
Sat 15/01/05 at 16:35
Regular
Posts: 10,364
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.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Impressive control panel
I have to say that I'm impressed with the features available having logged on... Loads of info - excellent.
Phil
Wonderful...
... and so easy-to-use even for a technophobe like me. I had my website up in a couple of hours. Thank you.
Vivien

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.