login.php
<html>
<head>
</head>
<body>
<form action="login_pro.php" method="post">
username<br />
<input type="text" name="unm">
<br />
<br />
password<br />
<input type="password" name="pwd">
<br />
<br />
<input type="submit" value="login">
</form>
</body>
</html>
login_pro.php
<?php session_start();
if (empty($_REQUEST['unm']) || empty($_REQUEST['pwd']))
{
echo "pleace enter username and password";
}
else
{
$link=mysql_connect("localhost","root","");
mysql_select_db("login",$link);
$unm=$_REQUEST['unm'];
$pwd=$_REQUEST['pwd'];
$q="select * from registration where unm='$unm' and pwd='$pwd'";
$res=mysql_query($q,$link)or die($row);
$row=mysql_fetch_array($res);
if(empty($row))
{
echo"wrong username or password";
}
else
{
$_SESSION['unm']=$row['unm'];
$_SESSION['status']=true;
header("location:index1.php");
}
}
?>
index1.php
<?php session_start();
if(isset($_SESSION['status']))
{
echo 'hello:'.$_SESSION['unm'];
echo '<a href="logout.php">Logout</a>';
}
else
{
header("location:logout.php");
}
?>
logout.php
<?php session_start();
session_destroy();
header("location:login.php");
?>
<html>
<head>
</head>
<body>
<form action="login_pro.php" method="post">
username<br />
<input type="text" name="unm">
<br />
<br />
password<br />
<input type="password" name="pwd">
<br />
<br />
<input type="submit" value="login">
</form>
</body>
</html>
login_pro.php
<?php session_start();
if (empty($_REQUEST['unm']) || empty($_REQUEST['pwd']))
{
echo "pleace enter username and password";
}
else
{
$link=mysql_connect("localhost","root","");
mysql_select_db("login",$link);
$unm=$_REQUEST['unm'];
$pwd=$_REQUEST['pwd'];
$q="select * from registration where unm='$unm' and pwd='$pwd'";
$res=mysql_query($q,$link)or die($row);
$row=mysql_fetch_array($res);
if(empty($row))
{
echo"wrong username or password";
}
else
{
$_SESSION['unm']=$row['unm'];
$_SESSION['status']=true;
header("location:index1.php");
}
}
?>
index1.php
<?php session_start();
if(isset($_SESSION['status']))
{
echo 'hello:'.$_SESSION['unm'];
echo '<a href="logout.php">Logout</a>';
}
else
{
header("location:logout.php");
}
?>
logout.php
<?php session_start();
session_destroy();
header("location:login.php");
?>
1 comment:
Va
Post a Comment