W3C validation Service online

Simple PHP User Login / SignUp Script Tutorial

simple php user login / signup script tutorial

(You can download complete “Simple PHP User Login / SignUp Script Tutorial” from the right sidebar.)

In this tutorial we are going to create simple php user login / signup script tutorial using php and mysql as database. In this script, a form will be displayed with two fields, username and password. When user is submitting with valid username and password, then he can access authenticated (my-account) page. Otherwise user again has to fill in the form.

Here are the files and directories that we are going to create.

  • css
  • - style.css
  •  
  • inc
  • - connection.php
  • - functions.php
  •  
  • index.php
  • signup.php
  • login.php
  • my-account.php
  • logout.php

We will be including connection.php and functions.php file at the top of each file. In connection.php file, we will store our databae info and create MYSQL Connection. functions.php file will contain our simple and mostly used functions.

let’s Create MySQL Table

Simple table with 3 columns named as ‘users’. You can also use your table as well if you have already created.

MYSQL Connection File connection.php

If you notice we are using PHP mysqli_query() here, not regular mysql_connect(), i = stands for improved extension, developed to take advantage of new features found in newer MySQL systems. PHP encourages everyone to use mysqli_* instead of regular mysql_* extensions, which will be totally removed in the future PHP versions.

Index Page: index.php

Sign Up Page: signup.php

Login Page: login.php

My Account Page: my-account.php

This is the main user’s account page where user will be redirect to after login. That page cannot be accessed directly without login.

Logout Page: logout.php

That page is fairly simple. We are just unsetting session variable which was set when user was logged in. Mostly people use session_destroy(); function which destroys all the session variables. But, I prefer to unset only specific variables like this one used in this file below.

Here is the style.css file

Finally add little styling to our pages.

In case you are wondering, here is what functions.php file looks like

You can download “Simple PHP User Login / SignUp Script Tutorial” from the right sidebar.