PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Register Login Script

Register Login Script


Register Login ScriptThe following tutorial will teach you how to add a login/register script to your site. This tutorial requires 6 files, and PHP with MySQL installed.

Simply upload all files to any directory, open connect.php and set the connection variables. After that simply run install.php once, and when it tells you it is installed, delete install.php

You can download all the files here. Install [install.php]


    require_once("connect.php");
    
    $query = mysql_query("
CREATE TABLE 'members' (
'id' MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT ,
'username' VARCHAR( 50 ) NOT NULL ,
'firstname' VARCHAR( 50 ) NOT NULL ,
'lastname' VARCHAR( 50 ) NOT NULL ,
'password' VARCHAR( 50 ) NOT NULL ,
'date' VARCHAR( 50 ) NOT NULL ,
'ip' VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( 'id' ) ,
UNIQUE (
'username'
)
)");

echo "Installed! Please delete this file.";
    

?>

Connect [connect.php]


    // MySQL connect information.
    $c_username = "database_username";
    $c_password = "database_password";
    $c_host = "localhost";
    $c_database = "database_name";

    // Connect.
    $connection = mysql_connect($c_host, $c_username, $c_password)
    or die ("It seems this site's database isn't responding.");

    mysql_select_db($c_database)
    or die ("It seems this site's database isn't responding.");

?>

Register [register.php]


// Check if he wants to register:
if (!empty($_POST[username]))
undefined

?>


    
        Register
    
    
        

            
                
                    
                
                
                    
                
                
                    
                
                
                    
                
                
                    
                
                
                    
                
                
                    
                
            
Registration

        

    


Login [login.php]

session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
undefined

?>


    
        Login
    
    
        

            
                
                    
                
                
                    
                
                
                    
                
                
                    
                
            
Login

        

    

Logout [logout.php]

    $_SESSION[username] = "";
?>

Want to limit certain files only to members, use the below script. Members [members.php]

session_start();

// Check his status.
if (!empty($_SESSION[username])) // he got it.
undefined
else // bad info.
undefined

?>


Author's URL: SweDesignz.com
PHP is open source scripting language. It\'s widely used to develop web applications. More PHP Tutorials: Featured Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Reader's comments
comments asdfas February 05, 2012 says:
asdfasdfasdf
Reply
comments RodzkieX December 28, 2011 says:
visit me my site, it helps me alot:
You can create new account by just visiting here:

Reply
comments ionas December 02, 2011 says:
thanx.it helps a lot.
Reply
comments IDE August 25, 2011 says:
i have created a db but is still can't login
Reply
comments alvin August 22, 2011 says:
im new how to upload this thing?
thanks

Reply
comments alvin August 22, 2011 says:
im new how to upload this thing?
thanks

Reply
comments anand July 15, 2011 says:
Nice and easy code for starters,but i m afraid its not working, i put in two different servers, it failed. and there is no function for it to sending the details to email..
advisor.bulljobs@gmail.com .... suggest me step by step

Reply
comments JOLAS May 10, 2011 says:
good day.. i have problem within line 4. the error say Notice: Use of undefined constant username - assumed 'username' in C:wampwwwsample3register.php on line 4. somebody help pls pls. thank you
Reply
comments gatsby June 19, 2011 says:
username, you should have "username" (with the double quotes).
Reply
comments jawad April 28, 2011 says:
nice script
Reply
comments rajeev April 28, 2011 says:
let me check

rajeevcse04.blogspot.com

Reply
comments Milojko April 17, 2011 says:
look this script
<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><script>window.google={kEI:"FPqqTZr3HMO0tAaWxY2aCQ",kEXPI:"17259,27084,29383,29456,29544",kCSI:{e:"17259,27084,29383,29456,29544",ei:"FPqqTZr3HMO0tAaWxY2aCQ",expi:"17259,27084,29383,29456,29544"},ml:function(){},pageState:"#",kHL:"en",time:function(){return(new Date).getTime()},log:function(c,d,
b){var a=new Image,e=google,g=e.lc,f=e

Reply
comments Plnstk April 08, 2011 says:
mktime() expects parameter 1 to be long, string given in
Reply
comments sourav kumar kar February 20, 2011 says:
great sir .. i want this and finally i get this... thanks alot...................................................
Reply
comments Dietmar February 11, 2011 says:
It looks like a lot have the same problem: It would be nice to have a sequence of the scripts.
1) you try to to go to a protected page
2) it tells you you are not logged in
3) you try to log in but you are not registered (how does he come to the register page)
4) you register and login
5) does the page with the code of members.php in to be saved as .php or is .htm as good?
6) where has this code to go to in the htm file?
Maybe I am the only one who does not know "How to" but sorry I am a beginner

Reply
comments Setiawan December 30, 2010 says:
father where we store these php
Reply
comments alex February 15, 2011 says:
ust trying the script
Reply
comments Ben December 20, 2010 says:
How should I create the database for this code
Reply
comments michael December 14, 2010 says:
I think it's a simple thing to do
www.qorser.com

Reply
comments vix November 19, 2010 says:
thanxxx lemme chk

BlackDrifter.com

Reply
comments Richard Andrews November 19, 2010 says:
Hi There,
I have a all forms in php showing problems, for instance: In the form register.php in desired username it shows <? echo $_POST[username]; ?> for First Name --> <? echo $_POST[firstname]; ?> etc.... How can I fix this errror? I am using PHP 5.2.9-2. I find the tutorial realy interessting and I'lll appreciate if someone can drop a tip to fix it. Thanks for any help. Richard Andrews.

Reply
comments MR November 12, 2010 says:
Thank you for this script it works great.

I got a question.
How do i use this script to secure 1 or more pages of my website ?
Cause <?php include('login.php'); ?>
cause it its will just add the login page to my normal page :(

greeting MR

Reply
comments MR November 12, 2010 says:
i mean that this code <?php include('login.php'); ?> will not work at all :(
Reply
comments lol September 14, 2010 says:
LOL for this not needed database, where are insert to database? :D
Reply
comments anonymous September 05, 2010 says:
It loggs me off when I restart page.. :[
Reply
comments Hud August 31, 2010 says:
Can i set this to redirect after a login?
Reply
comments Name November 12, 2010 says:
This is the code for redirect with a self timer of 4 you can set the timer to what ever you like just change the number.
header( "refresh:4;url=your url or page" );
header( "Location: your url or page" );
Hope this will help you abit unless you allready got it ofc :)

Reply
comments koki April 25, 2010 says:
hi all i tryed it but its not worked here is the site :
Reply
comments KOki April 25, 2010 says:
hi i has a problem i add all the php and then when i type allthing and click register! i get File Download "Register.php"....
Reply
comments Ash July 07, 2010 says:
You need php installed on your server - check with your hosting provider.
if using localhost the u need to install one of the following
mac - mamp
windows - wamp

just google for them

Reply
comments Bill king April 20, 2010 says:
Thanks! i will add to my website www.juicylacewigs.com
Reply
comments BJM March 27, 2010 says:
It seems to log me out right after logging in. I logged in, then went to a page that i protected, and it still wouldnt let me on it!
Reply
comments D'jems Mortimer February 15, 2010 says:
All it says is " you've successfully been logged in"
Reply
comments D'jems Mortimer February 15, 2010 says:
Ok, I createad the database. Everything works but How do you get it to authenticate users?
Please help

Reply
comments Kate Hanley April 04, 2010 says:
I also have the same question, How do you get it to authenticate users?
Reply
comments stefan epure February 12, 2010 says:
the onli one that worked for me thanx
Reply
Add comments to "Register Login Script"

Captcha