LOIGN-MODULE-CODE-IN-PHP

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>';

?>

Comments

Popular posts from this blog

Query to get concurrent Program details with Parameter list and value set attached to parameter.

AR and OM link in oracle apps / AR transaction and Sales Order join query

Japan Style: Architecture Interiors Design