PHP login system

PHP component ready to use to implement basic login features.


This is another
 PHP component ready to use and reuse in your project which implements a "ready to use" login system with PHP. In the past week I received several emails about the difficult (from some PHP beginners) to implement this functionality in their projects, in particular for these two common issues:

- cannot maintain session value after log-in if you visit a new page
- cannot redirect an user in a specific page after the login

So I prepared this component to help everyone which have the same problems. This post is not so short... but don't worry... It's just because I want to exagerate with the words to be clear :)

http://1.bp.blogspot.com/_TqPdHmAEwTM/R6Ds89u3tkI/AAAAAAAAA0U/biqUma6R5w4/s400/tag_orange.png
 Download this PHP component


Before to start
Take a quick look at the package content:

http://lh5.google.it/antonio.lupetti/R9mY9thRRqI/AAAAAAAABSw/ecLXCGUDzkU/login-3.png

 

 

 

 

 

 


In detail:

- login-form.php contains a standard form with two fields, email and password.
-
 common-functions.php contains two functions: redirect and remove HTML tag from the input field
-
 config.php includes DB connection parameters
-
 login.php contains a basic query to verify if an user exists and in this case it creates a PHP session.
-
 logout.php contains delete session code (if you are logged-in)


I supposed your
 login form has these fields: email and password. If login fails an error message will be displayed:

http://lh5.google.it/antonio.lupetti/R9mUHthRRoI/AAAAAAAABSg/KKTgPAvDzk0/login-1.png



 

 

...otherwise if login is ok will be displayed a simple logout link:

http://lh3.google.it/antonio.lupetti/R9mV7NhRRpI/AAAAAAAABSo/iaP2C4IS5zU/login-2.png


 

You can modify everything how you prefer customizing the code. How? Read the following paragraphs...

Step 1: include login-form.php
Create a new PHP page (for example
 index.php) in the same folder where is login-form.php (don't change it, ok?) :

http://lh3.google.it/antonio.lupetti/R9memNhRRrI/AAAAAAAABS4/Dng3RahsgHA/login-4.png


 

Open index.php and include login-form.php where you want into the <body>tag using:

<?php include('login-form.php')?>


...in this way you are including the login form into your page. Now, add this line of code
 on top of index.php before any kind of code in your page (it's important in order to mantain session created after the user login... you can't forgot it ok? Otherwise it doesn't work!):

<?php session_start(); ?>



Step 2: modify config.php
Change MySQL connection parameters in
 config.php:

http://lh4.google.it/antonio.lupetti/R9h5GthRRjI/AAAAAAAABR0/AP0Pfl2K2Ss/autosuggest-4.png


 

 

 

Step 3: modify login.php
You have to modify some parameters in
 login.php so that this component works well. In this example I used a table "USER" to store the user data (email, password, name...) so, in the line 13 in my FROM clausule there is "USER". Change it with the name of the table you have in your database which store the user data:

http://lh5.google.it/antonio.lupetti/R9miUthRRsI/AAAAAAAABTA/-TmP4cZCShs/login-7.png

 

 

 

 

 

 

 

 

 

It's a good practice using the primary key value to store a session ID. At line 19change ID_USER_PK with the name of the primary kay you have in the user data table.

Change
 line 25 and line 31 to customizing a redirect page when an user submit the login form.

Step 4: change redirect in logout.php
Last step, modify the URL to redirect an user in a certain page after logout:

http://lh6.google.it/antonio.lupetti/R9mmG9hRRtI/AAAAAAAABTI/Bqh2RIEe2eY/login-8.png



 

 

 

 

It's all! Tell me more infos if you have some problems with this component.

http://1.bp.blogspot.com/_TqPdHmAEwTM/R6Ds89u3tkI/AAAAAAAAA0U/biqUma6R5w4/s400/tag_orange.png
 Download this PHP component

New User?Register

Important Links

DOEACC Helpdesk

Download Sample C Language Programs

Interview Questions

Windows XP

Windows Vista

Windows 2000 Server

Windows Server 2003

Redhat Linux

Configure RAID in Linux

SUN Solaris

How To Install Sun Solaris

VMWARE

Microsoft Exchange Server

IBM Lotus Notes

C-Language

Java Script

PHP/MYSQL

c++

Desktops

Laptops

Servers

ThinClients

Printers

Terms Of Service
About Us | Site Map | Privacy Policy | Contact Us | Disclaimer

Best Viewed on 1024*768 Resolution