Members' Login Function With PHP 5

Hi!

Can anyone provide a simple code for Members to login.

I just need to see how it looks like to code a Member’s Login function with PHP. Thanks a million!!!

Wilson!

Did you try to search with some words in google? There are loads of examples link which google gives you for free.
http://www.google.com/search?q=php+login+scripts

It really depends on how you store your user data, how you store passwords: hashed in clear text or encrypted in such a way that they can be decrypted.

Basically you just need to create an html form that asks for username and password, then on the server select * from USER where username = $_POST[‘username’]
Then if record is found, proceed to compare password and if passwords match, then add something to $_SESSION that would indicate that user is logged-in.

You can add as little as just the id or user or the array of user data with username, first name, last name, and anything else. Or you can even create an object that represents user data and has methods to get more info for that user if necessary and then just put the entire object into SESSION, this is more advanced topic and requires some extra methods in the object so it serializes properly.

Then you can redirect user to another page and this time you will detect that user is already logged in by examining the $_SESSION and you can present a ‘welcome’ block in place of login block.

This is just an outline how this is done. In short - put logged in user data into $_SESSION, like $_SESSION[‘user’] = array of user data.

To put it blunt, a membership function consists of a lot more than what I assume you are thinking.

You’ll need a DB connection file, a DB, a registration system, and then at minimum, (unless you want to crowd yourself) 2 different pages for the process to take place.

Then you can start debating security, sessions, registration scripts, etc…

A better quey to use for that would be:

SELECT COUNT(*) as num_users
              FROM users_table
              WHERE user_name='$username'
              AND user_password='$password'";

Before running the query to check if the user exists, don’t forget to validate and escape the data. I suggest that instead when storing the password in the database, you store the sha1 hash of it and use a [URL=“http://en.wikipedia.org/wiki/Salt_%28cryptography%29”]salt. When a user attempts to login you would create a sha1 hash of the password they are attempting to use and compare it with the sha1 hash stored in the database.

Good article which worth reading:
http://www.evolt.org/article/PHP_Login_System_with_Admin_Features/17/60384/index.html

provided class in php4 which can easily be converted to php5.

Also I found one very good article from sitepoint which i read 1-2 years ago:
http://articles.sitepoint.com/article/anthology-2-1-access-control

Hi.
Please refer to the url below:
http://www.ineedtutorials.com/code/php/complete-advanced-login-member-system-php-tutorial
I believe it is useful for you.
Regards,
freezea.

This is the member login script I used before. It’s pretty complete.

Off Topic:

What are you talking about? What do you mean by above?

Off Topic:

it’s spam :stuck_out_tongue:

I mean no disrespect, but a simple glance at your code shows that it’s vulnerable to SQL Injection, stores passwords in plain text and uses PHP 4. It’s disingenuous at best to pass this off as a legit way to store user logins.

@SituationSoap
AFAIK, links are provided to just grab the concept not to copy blindly.
If one know how to convert to PHP5 & deploy the security factors that’s up to them.