php full session tutorial

Hey, There! “session” is an important concept in php, which we are going to study it full in this tutorial. The code will use a mysql Database with the php back end for user registration, login to portal, retrieving data from the database using session variables and logout. This tutorial will also use a redirect scheme to login page in case the user is not logged in.

Creating Database

So lets start this tutorial with the database. First of all, we’ll create a database with any name (in my case, it is Technopoints). execute the following SQL query inside database to create the table, rows and columns automatically.

Connect with database

Now create the database file dbconfig.php like this tutorial and paste the following connection code in it.

Set sessions

Creating a structure of session

Now it is the time of creating session variables. create the file class.user.php with the following code. It has various functions to Login and Register the user. It is embedded in the class name “USER”.

The above file will make all the session management. We have to create the further file as session.php to set the session after successful login.

Manage login and logout events

Are you thinking in the above file has no “?>” php end tag? Actually,here no need of it as the file contains only php code.It will automatically ended. Thus, the session variables are ready to work.

Creating the main structure

Create login window

Now,lets design a homepage index.php and paste the following code in it.

You’ll see the following look after opening this file.

php full session tutorial

Build Dashboard

Now we have to build the dashboard file where the user will be redirected after successful login. So, code home.php as follows.

As a result of above code, you’ll see the following view after successful login.

php full session tutorial login window

In the login view, there is Logout button. In order to unset the session and redirect the user to login page, we create the following file as logout.php.

Creating Registration form

Now, we will also include the facility to create the new user and assign the separate panel to it. so create file sign-up.php and paste the following code in it.

See the signup form below. After filling the details and clicking on sign up button, user registration will be done.

php full session tutorial registration window

Finally, add styling by provided some css files for a better look. Following style.css will cover it.

Also you can get additional almost all css files after downloading the zip file below. Probably, it will not impact the back end performance.
That’s it! Now we have built the complete login and signup system using php and mysql backend.
Hope you liked it. Stay tuned for more tutorial 🙂

If you have any difficulties in this tutorial, feel free to download the source code from below link.

Download Source Code

3 thoughts on “php full session tutorial

  1. L
    Lina says:

    Thank you for the good writeup. It in fact was a amusement account
    it. Look advanced tto more added agreeable from you!However,
    how could we communicate?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.