SEARCH
Newsletter
Subscribe to get design
tips, latest trends, free
stuff and more.
It doesn't look like an e-mail address

hosting

  Web Programming PHP Register Login Script

Register Login Script

SweDesignz.com PHP Jun 16, 2006

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

?>

   
subscribe to newsletter