With our free user login script.

- MySQL is used to store the user database.
- You can define custom messages to each user upon login.
- Add nice and clean login form to your website.

Review the Demo to test the PHP User Login Script. Use the following details to log in:

password: pass


password: pass

Download the Simple PHP Login Script for FREE. Note you need to be logged in to download the user login script.

Also, check our fully supported Member Login Script.


To download Simple PHP User Login Script for FREE you need to login your account.

how to install

Follow these steps to run the PHP User Login Script:

1) open database.sql and import all the MYSQL queries in your database. There are two demo users which you can delete.

2) edit options.php file and set MySQL login details to connect to your database

3) using your web browser open index.php page which will show the login form.
301 Comments to "Simple PHP User Login Script"
  • Robert Mallett

    Robert Mallett

    December 4, 2017 at 13:18 pm

    Doesn't work with php 7

    • Robert Mallett

      Robert Mallett

      December 4, 2017 at 14:42 pm

      I tried changing mysql_connect by mysqli_connect and same for mysql_select_db to mysqli_select_db($connection, database)

      but I then get

      Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in /home/linweb17/s/ Stack trace: #0 {main} thrown in /home/linweb17/s/ on line 64

    • gdu


      December 4, 2017 at 14:45 pm

      Thank you for your information...
      If it is here it is that the maintainer thinks it is still worth leaving it here.

      Please check comments before posting...
      for example, check: October 4, 2017 at 12:53 pm

  • gehad


    December 3, 2017 at 19:27 pm


  • Mark Pulsinelli

    Mark Pulsinelli

    October 23, 2017 at 19:42 pm

    'Hi, this is great and was really easy to implement. Just one question, what php code do I need to put on the pages I want to require login for.

    • Andrew Barrington

      Andrew Barrington

      October 24, 2017 at 10:50 am

      Good luck getting this answer, it has been asked many times with no reply :(

    • gdu


      October 24, 2017 at 11:50 am

      This is because you need to read the code... and understand what it does.

      Here is what I did:

      <?php if(isset($_SESSION['user_info']) && is_array($_SESSION['user_info'])) { ?>
      <div id="form-content">
      <?php include("pagesvideos.php"); ?>

  • Nyle


    September 4, 2017 at 16:16 pm

    Personally I tried almost few hours to work with this, but for me never worked. "Unable to connect to MySQL server. Please make sure your MySQL login details are correct."
    May be this error because of I am very new To PHP. :(, if anyone can list the clear step by step will help very much. Thank you

    • gdu


      October 4, 2017 at 12:53 pm

      Using PHP7?.... change mysql_connect by mysqli_connect and same for mysql_select_db to mysqli_select_db($connection, database)

  • Patrick


    August 31, 2017 at 05:19 am

    Very nice script. Very helpful and free : )

  • Php Freelance Developer

    Php Freelance Developer

    August 4, 2017 at 15:35 pm

    Nice one. This was so easy to follow and exactly what I was looking for.


  • santiago


    July 30, 2017 at 01:08 am

    Hi, can you help me how to add another php page so it can be access only by login? is session start right?. it was asked, but no answer.

  • Javier


    June 7, 2017 at 01:28 am

    Hi, please help me, I can't get access to my account.

  • Ruben


    May 25, 2017 at 05:51 am

    I realy like this simple login, but anything is missing to complete the login.
    error: request "Could not execute SQL query" UPDATE login SET last_login = NOW() WHERE id=1
    You can help me, please?

  • Andrew Barrington

    Andrew Barrington

    April 13, 2017 at 14:55 pm

    Great Script thanks... however
    I would like to add a redirect upon login to another would i go about this?

    • Sasho Valkanov

      Sasho Valkanov

      April 14, 2017 at 09:14 am

      In index.php file after line 68 you can add the redirect. So the IF code will become

      $_SESSION['user_info'] = $user;
      $query = " UPDATE ".$SETTINGS["USERS"]." SET last_login = NOW() WHERE id=".$user['id'];
      mysql_query ($query, $connection ) or die ('request "Could not execute SQL query" '.$query);
      header("Location: newpage.php");

    • A


      April 25, 2017 at 03:43 am

      could you clarify this code a little further? it doesn't seem to be working

    • Andrew Barrington

      Andrew Barrington

      April 26, 2017 at 10:30 am

      This worked perfectly for me. Thank you very much.

    • Andrew Barrington

      Andrew Barrington

      April 27, 2017 at 13:19 pm

      One more question i have is, how do i then make the 'newpage' part of the existing session so that it is not accessible directly only via login. im not sure of the correct procedure for using 'session_start'.


Add your comment