23 thoughts on “Simple PHP Login Script using Session

    1. This script is not for multiple user!. Anyway If you want to use more than one, you can add one more username and pass in the if condition like this!

      if(($_REQUEST[‘uname’] == ‘admin’ && $_REQUEST[‘pass’] == ‘admin123’) or ($_REQUEST[‘uname’] == ‘gunju’ && $_REQUEST[‘pass’] == ‘gunju123’))

  1. Thank you so much for this code working without a database.
    I will add a multiple user function through an array of [user,pass].
    I will use it in my little wiki opensource project alphawiki.
    Alain Marty

    1. remove line no. 26 to 28.

      change this line

  2. Thanks for this – works perfectly. A smal question – how long does the session last?

    1. store the $_REQUEST[‘uname’] in a session like this
      $_SESSION[‘username’] = $_REQUEST[‘uname’];

      then print it in any file
      echo $_SESSION[‘username’];

      1. Thank you but that doesn’t work. Started the session at the top of the page and echo’d what you pasted. Just doesn’t show up.

  3. When i run this in wamp the code runs fine but when i run it on my server live it returns a blank page instead. any ideas why?

    1. Hi Dave, There is no special function used in this code. Have you tried any other php script in your server?. Is that working?.

  4. Can you explain to me how to echo the username in another file? For example, at the admin panel.

    1. Hi, Store the username in a session
      $_SESSION[‘uname’] = $_REQUEST[‘uname’]; (in this example may be after line no 11)

      echo this $_SESSION[‘uname’] wherever you want.

  5. The script I have downloaded a while ago and since my service provider migrated to PHP 5.4.4 it does no longer work. After the initial login, witch works, it shows “This web page has a redirect loop” at the second page I call up.

Leave a Reply

Theme: Overlay by Kaira