Creating Form Sign Up / Register, Login and Logout

1 komentar 1012 views
unmetered
unlimited
Creating Form Sign Up / Register, Login and Logout for the development of a web -based members nowadays has become a trend for webmasters who want to build a web that “look professional ” . In this article will explain the tutorial to create a form to sign up and login and logout is still a simple form . Henceforth , you can create your own development of this script .

 
The first step , you have to create the file ” config.php ” . This serves to connect the script file that you created with the database . The contents of the file ” config.php ” can you see below
< ? php $ server = ” localhost ” ; / / your web server . $ database = ” mydata ” , / / name of the database you created . $ DB_USER = ” myusername ” ; / / username of your mysql . $ db_pass = ” mypassword “/ / password to access your mysql is . $ table = ” users ” , / / name of the table to be created in the database . ? >
Save the file in your web root . Once completed , you can proceed to the second stage . Create a file with the name ” create.php ” . This file serves to run a database query command in the making of this table signup and login . The contents of this file you can see below .
< ? phpinclude ( ” config.php ” ) ;/ / connect to the MySQL server $ link = mysql_connect ( $ server , $ DB_USER , $ db_pass ) or die ( ” Could not connect to mysql Because ” . mysql_error ( ) ) ;/ / databasemysql_select_db select ( $ database ) or die ( ” Could not select database Because ” . mysql_error ( ) ) ;/ / make a table in the database $ create = “create table $ table ( id smallint ( 5 ) nOT NULL auto_increment , username varchar ( 30 ) nOT NULL , password varchar ( 32 ) nOT NULL , PRIMARY KEY ( id ) , UNIQUE KEY username ( username ) ) ; ” ; mysql_query ( $ create) or die ( ” Could not create tables Because ” . mysql_error ( ) ) ; echo ” Mangstabs ! ? now proceed to the third stage ” ; ? >
Now you need to create a form that visitors use to sign up and give it the name ” register.html ” . The file that you create should be a regular HTML page that will be connected to a php script that will you will make. For a simple test , you can copy the script below on the new Dreamweaver page .
<html> <head> <title> MEMBER REGISTRATION < / title> < / head> <body> <FORM action=”register.php” method=”post”> Choose a Username : < input type = “text ” name = ” username ” size = ” 20 ” > Reviews Choose a Password : <input type=”password” name=”password” Reviews size=”20″> <input type=”submit” value=”Sign Up”> < / form> < / body> < / html >
After that, create a file with the name ” register.php ” . This file will serve as an intermediary that connects register.html file on the database that you have created . For the contents of the file ” register.php you can see below .

< ? phpinclude ( ” config.php ” ) ;/ / connect to the MySQL server $ link = mysql_connect ( $ server , $ DB_USER , $ db_pass ) or die ( ” Could not connect to mysql Because ” . mysql_error ( ) ) ;/ / databasemysql_select_db select ( $ database ) or die ( ” Could not select database Because ” . mysql_error ( ) ) ;/ / check similarity username
$ qry = mysql_query ( $ check ) or die ( ” Could not match Because the data ” . mysql_error ( ) ) ;$ NUM_ROWS = mysql_num_rows ( $ qry ) ;if ( $ NUM_ROWS ! = 0 ) {echo ” Sorry , the username $ username already taken Reviews ” ;echo ” <a href=register.html> lucky you have not , please try again < / a> ” ;exit ;Else { }/ / Insert the data$ insert = mysql_query ( ” insert into $ table values ​​( ‘ NULL ‘ , ‘ ” . $ _POST [ ‘ username ‘ ] . ” ” ” . $ _POST [ ‘ Password ‘ ] . ” ‘ ) ” )or die ( ” Could not insert the data Because ” . mysql_error ( ) ) ;/ / Show success messageecho ” Your account has been created ! Reviews ” ;echo ” Now you can <a href=login.html> Login as a web Cyber4rt < / a> ” ;}? >Now you need to create a form member to login . Rate this file with the name ” login.html ” . The contents of this file are as follows :
<html> <head><title> MEMBER LOGIN < / title>< / head> <body><FORM action=”login.php” method=”post”>Username : <input type=”text” name=”username” size=”20″> ReviewsPassword : <input type=”password” name=”password” size=”20″> Reviews<input type=”submit” value=”Log In”>< / form>< / body> < / html >
Now you need to create a file that will connect to the database login.html file , give the file name with ” login.php ” . The script you can see below .
< ? phpinclude (” config.php ” ) ;/ / Connect to MySQL server$ link = mysql_connect ( $ server , $ DB_USER , $ db_pass )or die ( ” Could not connect to mysql Because ” . mysql_error ( ) ) ;/ / Select databasemysql_select_db ( $ database )or die ( ” Could not select database Because ” . mysql_error ( ) ) ;$ match = ” select id from $ table where username = ‘ ” . $ _POST [ ‘ username ‘ ] . ” ‘and password = ‘ ” . $ _POST [ ‘ password ‘ ] . ” ‘ ; ” ;$ qry = mysql_query ( $ match)or die ( ” Could not match Because the data ” . mysql_error ( ) ) ;$ NUM_ROWS = mysql_num_rows ( $ qry ) ;if ( $ NUM_ROWS < = 0 ) {echo ” Sorry , there is no username $ username with the password . <br> ” ;echo ” <a href=login.html> Try again < / a> ” ;exit ;Else { }setcookie ( ” loggedin ” , ” TRUE ” , time ( ) + ( 3600 * 24 ) ) ;setcookie ( ” mysite_username ” , ” $ username ” ) ;echo ” You have logged in ! Reviews ” ;echo ” Continue to <a href=members.php> member < / a> area . ” ;}? >
Note the file pad the bottom third row , there members.php contains <a href=members.php> this is an area that can only be seen by the members . You can create files members.php own creations . Now I will explain the scripts used to check the cookie , if the person is logged in or not . Save this scipt throughout the area members . The script as follows :

< ? php if ( isset ( $ _COOKIE [ ‘ loggedin ‘ ] ) ) die ( ” You ‘re not logged in ! Please login first ” ) ; $ mysite_username = $ HTTP_COOKIE_VARS [ ” mysite_username ” ] ; echo ” You are logged in as $ mysite_username . ” ; ? >
Finally, the last script is a script to logout . This script can be connected by a link on a regular html . This link is placed in the member area . View the contents of the script below :

< ? php / / active period cookiesetcookie ( ” loggedin ” , ” ” , time ( ) – 3600 ) ; echo “You have been logged out . <br> ” ; echo ” <a href=”login.html”> Login < / a> . ” ; ? >
For the lawyer ‘s application of scripts that I described above , you can own creations . Congratulations to create . ! ! ! ! ( Www.web.unmetered.co.id )

unlimited
author
Satu Respon
  1. author

    health and beauty offers4 bulan ago

    I like this blog so much, saved to favorites.

    Balas

Tinggalkan pesan "Creating Form Sign Up / Register, Login and Logout"