PHP Login System Reloaded

Update: There’s a new version of this Login Script. Here’s a PHP Login System, based on the one developed by jpmaster77: PHP Login System with Admin Features Focusing only on the core functionalities and aimed to improve certain parts of the code, I took out some functionalities and added some others: Removed: Admin features Active […]

From our sponsor: Don't spend all day sending messages. Automatically reach out to fans based on how they behave.

Update: There’s a new version of this Login Script.

Here’s a PHP Login System, based on the one developed by jpmaster77: PHP Login System with Admin Features
Focusing only on the core functionalities and aimed to improve certain parts of the code, I took out some functionalities and added some others:

Removed:

  • Admin features
  • Active guests, active users, banned users
  • Global variables
  • Links to other pages after the login

All these can be easily reintegrated if you want. I focused on the login and registration part, leaving out the content “inside”.

Added:

  • PHP 5 instead of PHP 4
  • mysqli extension
  • Send registration confirmation link to the email address
  • Reset password feature without sending password to the email. Instead a link is sent to reset the password
  • UTF8 support
  • InnoDB transactions for database operations
  • Registration and form validations made with AJAX
  • jQuery
  • Captcha image in registration form to avoid spam

Here are the most important settings for the installation of the login system.
Set database access in constants.php:

define("DB_SERVER", "localhost");	//type mysql server url
define("DB_USER", "XXXXXXX");		//type mysql user
define("DB_PASS", "XXXXXXX");		//type mysql password
define("DB_NAME", "XXXXXXX");		//type mysql database name

Further, you have to set the right location of the following files for the mail sending functions:

define("RESETPASSWORDLINK","http://www.tympanus.net/loginsystem/resetpassword.php");
define("CONFIRMACCOUNTLINK","http://www.tympanus.net/loginsystem/php/confirm.php");

The only table that you have to create in your MySQL database is the following:

CREATE TABLE users(
pk_user int unsigned not null auto_increment,
email 	varchar(120) not null,
flname varchar(100) not null,
password varchar(64) not null,
usr_signup_date timestamp not null default CURRENT_TIMESTAMP,
usr_userid varchar(32),
# for the account confirmation:
usr_confirm_hash varchar(255) not null,
# after confirming its set to 1:
usr_is_confirmed tinyint(1) not null default 0,
# when the user resets password (forgot password):
usr_resetpassword_hash varchar(255) not null,
unique index(email),
primary key(pk_user)
)type=innodb DEFAULT CHARACTER SET utf8	COLLATE utf8_general_ci;

I will soon post a new version, as I am currently improving some points.

See a demo here: PHP Login System Demo

You can download the source code here: PHP Login System ZIP

Tagged with:

chadking

Chadking is an absolute geek that rarely leaves the comfort of his 3-screen desk. He is a self taught programmer and is addicted to all possible legal drugs.

http://tympanus.net/codrops/author/chadking/

Stay up to date with the latest web design and development news and relevant updates from Codrops.

CSS Reference

Learn about all important CSS properties from the basics with our extensive and easy-to-read CSS Reference.

It doesn't matter if you are a beginner or intermediate, start learning CSS now.

Feedback 71

Comments are closed.
  1. dear sir,

    i am stil lencountering that error. there were some tagg where you havent added the php part

  2. Dear sir,
    I fixed the problem there are lot of <? in da index or login page. which needs to be replaced plus i have missed some of the <? tags . now the real fight begins to add features for this:D

  3. how to i configure the mailer settings for smtp and can u use the phpmailer for this. what would be the best option

  4. Hi,
    I’m not sure if I can help you with that. i didnt do much in my local machine. I tried with xampp once and I remember that no mail server is configured or it doesnt actually include one. I guess you have to try to find out how to install one if you want to run this system locally. Maybe somebody that posted here can give us a tip!?
    greetings

  5. oh and one more thing sir..can u give me some good tips to learn jqquery. because i am at a beginner level, when it comes to jquery

  6. This is such great timing for me. I have a project that could really use this and I stumbled onto your site after checking out the original login script. I’m wondering three things that maybe you would be able to help with.

    First, how do I add back in the edit account feature.

    Second, is there a way to mass-register a list of users and then send them an email with their username and password?

    Third, I need to use the My Account link to load a user-specific HTML page.

    I would love any help you could give me and if it’s complicated I would be interested in hiring you to work on it with me. If you are interested please shoot me an email.

    Thanks for the great script!

  7. hello again Mr chad,
    thanx for your helpful and valuble helps 🙂
    if u free enough to answer i may want to know how can i add more features to like
    First name
    Last name
    address
    ….etc
    to our registation form i already add those feialds to data base i just want to knw how can i link those with my web site. 🙂

    greetings!!!!! 😉

    • Hi,
      In the next version, I will put more fields in the registration form. I will update the script this week. Anyway if you wish to do that by yourself, here’s the list of steps you should do:

      1. register/index.php
      add all fields in the html form that you want. Check how the email is done.
      2. php/core.php
      you have to change the functions “processRegisterx” and “__register” to include these new fields, and to make the validations if you wish so.
      3. php/dbcontroller.php
      you have to change the function “dbregister” to include these new fields.

      greetings

  8. I tried using the source code on my server but it seems that the captcha isnt working it just prints the link but no image any ide how to fix it

    btw: a great script got even better

    • Hi Rick,
      do you have the same directory structure like in the downloaded file? Did you change something or removed perhaps some folder? Can you check with firebug the src attribute of the picture? Should be something like “../images/captcha/image.jpg?1253140450”!?
      greetings

  9. Pingback: PHP Login System Reloaded v1.1 | Codrops

  10. Hi Chad.

    Is there a way that we configure our system to confirm registration locally ie if one is working on a localhost and i av not hosted my site to an external domain ie with a .com, .net etc?
    this is because i av realized that the registration process does not accept an address like… me@localhost it gives a reply as invalid address.

    find something since i need to be confirmed locally coz my mailsever is local therefore cannot send to an external domain.

    another thing, is there away i can delete data from table eg. the registration info name,email and password?

    answer to SMTP setup
    ; Setup for Windows systems
    SMTP = smtp.my.isp.net or localhost
    sendmail_from = me@myserver.com or @localhost

    Setup for Linux systems
    sendmail_path = /usr/sbin/sendmail -t
    sendmail_from = me@myserver.com

    find php.ini and make the changes.

    Thank you.

  11. dear sir, chad

    I am having dificulty finding a “forum” script..with the admin power to edit the forum. and members to post. can u help me to find one.

    thnk u!

  12. Hi,
    As far as I understood you want that the User is redirected to the retricted.php after the login? In that case you could do something like

    I use if(!$session->logged_in)
    {
    header(”Location: login/main.php”) <= Login script } else header(”Location: xxx/restricted.php”); Is it this that you want?

  13. Hi,

    No.

    Using JP script, when user is authenticated successfully, he will be remained in his user profile (edit, logout, etc).

    The flow I would like to have is:
    when accessing url a (if not logged in) -> login -> back to url a
    when accessing url b (if not logged in) -> login -> back to url b

    hope this is clear.

    Rgds,
    Francis

    • Hi,

      I would use SESSION variables to store the url that the User wanted to go. So, if the User types xxxx/restricted.php you do:

      if isLoggedIn{
      show page...
      }
      else{
      $_SESSION['page'] = $_SERVER['PHP_SELF'];
      header("Location: public_html/index.php");//this goes back to login
      }

      then after the User is logged in (in my script he goes back to public_html/index.php) you check:

      if isLoggedIn{
      if isset $_SESSION['page'] then
      header("Location:".$_SESSION['page']);
      else
      show the user profile page
      }
      else{
      show the login form
      }

      greetings