/ Published in: PHP
How to build a login form using php with mysql database.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//================================================ db.php <?php $DB_hostname = "hostname"; $DB_user = "username"; $DB_password = "password"; $DB_name = "dbname"; ?> //================================================ login.php <?php include("db.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { // to validate username (length between 5 and 20) (contaning characters A-Z or a-z or _) echo '<B><FONT SIZE="4" COLOR="#FF0000">error: bad username</FONT></B>'; } else{ // to encrypt login password, also password stored in database is encrypted. $sql="SELECT * FROM user_tb WHERE login='$myusername' and password='$md5_password'"; if($count==1) { $_SESSION['login_user']= $myusername; $_SESSION['login_name']= $row['name']; } else { echo '<B><FONT SIZE="4" COLOR="#FF0000">incorrect login or password </FONT></B>'; } } } ?> <form action="" method="post"> <label>user login :</label><input type="text" name="username"/><br> <label>Password :</label><input type="password" name="password"/><br> <input type="submit" value=" Submit "/><br> </form> //================================================ logout.php <?php ?> //================================================ index.php <?php $S_login_user = $_SESSION['login_user']; $S_login_name = $_SESSION['login_name']; ?> <body> <h1>Welcome :<?php echo $S_login_name; ?></h1> <A HREF="logout.php">logout</A> </body>
URL: http://function-code.blogspot.com/2013/04/make-php-login-script.html