php login page example
TRANSCRIPT
Love this PDF? Add it to your Reading List! 4 joliprint.com/mag
9lessons.info
PHP Login Page Example.
This post for PHP beginners Login Page Example. I want to explain creating database, posting form values, storing the session value and destroy the session. It’s is very useful and simple. Try live demo with Username : test Password : test
Download Script Live Demo D a t a b a s e
MySQL admin table columns id, username, pass-code.
CREATE TABLE admin ( id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(30) UNIQUE, passcode VARCHAR(30) ); Config.php Database configuration file.
$mysql_hostname = «hostname»; $mysql_user = «username»;
$mysql_password = «password»; $mysql_database = «database»; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(«Opps some thing went wrong»); mysql_select_db($mysql_database, $bd) or die(«Opps some thing went wrong»); Login.php Contains PHP and HTML code.
include(«config.php»); session_start(); if($_SERVER[«REQUEST_METHOD»] == «POST») {
// username and password sent from Form $myusername=addslashes($_POST[‘username’]); $mypassword=addslashes($_POST[‘password’]); $sql=»SELECT id FROM admin WHERE username=’$myusername’ and passcode=’$mypassword’»; $result=mysql_query($sql); $row=mysql_fetch_array($result); $active=$row[‘active’]; $count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { session_register(«myusername»);
Thursday, September 24, 2009
http
://w
ww
.9le
sson
s.in
fo/2
009/
09/p
hp-lo
gin-
page
-exa
mpl
e.ht
ml
Page 1
Love this PDF? Add it to your Reading List! 4 joliprint.com/mag
9lessons.info
PHP Login Page Example.
$_SESSION[‘login_user’]=$myusername; header(«location: welcome.php»); } else { $error=»Your Login Name or Password is invalid»; } }
<form action=»» method=»post»>
<label>UserName :</label>
<input type=»text» name=»username»/><br />
<label>Password :</label>
<input type=»password» name=»password»/><br/>
<input type=»submit» value=» Submit «/><br /> lock.php Session verification. If no session value page redirect to login.php
include(‘config.php’); session_start(); $user_check=$_SESSION[‘login_user’]; $ses_sql=mysql_query(«select username from ad-min where username=’$user_check’ «); $row=mysql_fetch_array($ses_sql);
$login_session=$row[‘username’]; if(!isset($login_session)) { header(«Location: login.php»); } welcome.php
include(‘lock.php’); <h1>Welcome <?php echo $login_session; ?></h1> logout.php SignOut Destroy the session value.
session_start(); if(session_destroy()) { header(«Location: login.php»); }
Thursday, September 24,
http
://w
ww
.9le
sson
s.in
fo/2
009/
09/p
hp-lo
gin-
page
-exa
mpl
e.ht
ml
Page 2