login.php
<?php
session_start();
if($_SESSION['user']=="Please Enter a Valid User Name"){
echo $_SESSION['user'];
}
else if($_SESSION['status']=="admin"){
header('Location:login.php');
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
User Login
<form method="post" action="logindb.php">
Username : <input type="text" name="uname"/>
Password : <input type="password" name="pword"/>
<input type="submit" value="Login" /><br/>
</form>
</body>
</html>
Login database
<?php
$uname=$_POST['uname'];
$pword=$_POST['pword'];
mysql_connect("localhost","root","");
mysql_select_db("test1");
$query = "SELECT * FROM user WHERE username = '$uname' AND password = '$pword'";
$result = mysql_query($query);
if(mysql_num_rows($result)==1){
$row = mysql_fetch_array($result);
$name=$row['username'];
$status=$row['status'];
if($status=="admin"){
session_start();
$_SESSION['user']=$name;
$_SESSION['status']=$status;
header('Location:cat.php');
}
}
else{
session_start();
$_SESSION['user']="Please Enter a Valid User Name";
header('Location:login.php');
}
?>
cat.php
<?php
session_start();
if($_SESSION['user']==''){
header("Location:login.php");
}
?>
<html>
<head>
<title>cat</title>
</head>
<body>
<a href="cat.php">cat>></a>
<?php
echo "Welcome ".$_SESSION['user'];
?>
<a href="logout.php">Logout</a>
<ul>
<li><a href="update.php" float:right>update</a></li>
<li><a href="enter.php" float:right>Enter</a></li>
</ul>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
header ('Location:login.php');
?>
<?php
session_start();
if($_SESSION['user']=="Please Enter a Valid User Name"){
echo $_SESSION['user'];
}
else if($_SESSION['status']=="admin"){
header('Location:login.php');
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
User Login
<form method="post" action="logindb.php">
Username : <input type="text" name="uname"/>
Password : <input type="password" name="pword"/>
<input type="submit" value="Login" /><br/>
</form>
</body>
</html>
Login database
<?php
$uname=$_POST['uname'];
$pword=$_POST['pword'];
mysql_connect("localhost","root","");
mysql_select_db("test1");
$query = "SELECT * FROM user WHERE username = '$uname' AND password = '$pword'";
$result = mysql_query($query);
if(mysql_num_rows($result)==1){
$row = mysql_fetch_array($result);
$name=$row['username'];
$status=$row['status'];
if($status=="admin"){
session_start();
$_SESSION['user']=$name;
$_SESSION['status']=$status;
header('Location:cat.php');
}
}
else{
session_start();
$_SESSION['user']="Please Enter a Valid User Name";
header('Location:login.php');
}
?>
cat.php
<?php
session_start();
if($_SESSION['user']==''){
header("Location:login.php");
}
?>
<html>
<head>
<title>cat</title>
</head>
<body>
<a href="cat.php">cat>></a>
<?php
echo "Welcome ".$_SESSION['user'];
?>
<a href="logout.php">Logout</a>
<ul>
<li><a href="update.php" float:right>update</a></li>
<li><a href="enter.php" float:right>Enter</a></li>
</ul>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
header ('Location:login.php');
?>
No comments:
Post a Comment