PDA

View Full Version : Usernames & Passwords


ionsurge
11-19-2002, 01:57 PM
Hello all.


Can anyone let me know how I can go about creating the ability to allow users to login and register to my site via php?

You can see what I mean anywhere, but I intend to allow users to be able to log in, and allow them to have high scores etc. However, that is besides the point.

All I am asking for is some sort of tutorial, or step by step guide, or an example source code which will help me learn how I can go about this.

Once the user has logged in, I also want the word "Guest" to change into the users registered username. (Go to www.ionsurge.com/test to see what I mean)


Cheers all.



Ionsurge.

freakysid
11-20-2002, 12:41 AM
Here is a page with links to tutorials on this subject:
http://www.hotscripts.com/PHP/Tips_and_Tutorials/User_Authentication/

Generally you want to do something like this. Have a script that gets included into every page that requires user authentication.

session.inc.php

// check whether the user has a valid session
if (! isset($_SESSION['loggedin'])) {
include('login.php');
exit;
}

login.php will contain a form where the user enters their username and password. Your script will then process this form data and lookup the user in the database and validate their password.

// assume we have done the database lookup
// and we have validated the user
// now we just got to start the session.
// Also assume that we have the user's name stored
// in $username

$_SESSION['loggedin'] = &$username;

Now when you need to know the user's name it will be in the session variable:

$_SESSION['loggedin']

ionsurge
11-20-2002, 09:09 AM
Cheers mate, I will look into it as soon as I get home.


Ionsurge.