Thursday, 30 July 2015

LOIGN-MODULE-CODE-IN-PHP

02:54

Login Module with session  Management:


(1)First create  databse & table  & insert values  for username & password:
Create database   amrapali;  
Create table  user
(id   int  primary key auto_increment,
username   varchar(20),
password   varchar(20));

(1)    Write html code for  “Loginform.html”  file , CODE IS GIVEN BELOW:
<html>
<head>
<title>
login example
</title>
</head>
<body>
<form action="login.php"    method="post">

username <input type=text    name="username">

Password <input type=text name="password">

<input type="submit"   name="submit" value="submit">

</body>
</html>






(2)write php code  which will check username & password   “login.php”  file CODE IS GIVEN BELOW:
<?php

$con=mysqli_connect("Localhost","root","","amrapali");



$username=$_POST['username'];

$password=$_POST['password'];

$sql="select  username , password from  user where username='$username' AND password='$password'";

$result=mysqli_query($con,$sql);

$num=mysqli_num_rows($result);

if($num>0)
{

session_start();

$_SESSION['username']=$username;

header('Location:welcome.php');

}

else
{

echo "invalid login";

}

?>














(3)AFTER LOGIN  page will display that is  “welcome.php”:
<?php

session_start();

if(!isset($_SESSION['username']))
{

header("Location:error.php");

}


echo "<h1>welcome </h1>";


echo '<a href="logout.php">Logout</a>';




?>



(4)logout.php   file this file destroy session:
<?php

session_start();

session_destroy();

header("Location:loginform.html");

?>

(5)error.php file:

<?php

echo "first make login ";

echo '<a  href="loginform.html">Login here</a>';

?>



Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

1 comments:

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top