login
<?php
session_start();
mysql_connect("localhost","root","") or die(mysql_error);
mysql_select_db("tutorial") or die("could not select database");
if(isset($_SESSION['loggedin']))
{
echo "you are already loggeddin";
}
if(isset($_POST['submit']))
{
$name=$_POST['username'];
$pass=$_POST['password'];
$res="select * from users where name='$name' and password='$pass'";
$result=mysql_query($res);
if(mysql_num_rows($result) < 1)
{
die("Password incorrect try again !");
}
$_SESSION['loggedin']= "YES";
$_SESSION['name']=$name;
die("Login Successful");
}
echo "
<form name='frm' method='POST'>
Username : <input type='text' name='username'> <br>
Password : <input type='text' name='password'><br>
<input type='submit' name='submit' value='submit'>";
?>
-----------------------
logout
<?php
session_start();
session_destroy();
header("location:login.php");
?>-------------------------
chk session
<?php
session_start();
if(!isset($_SESSION['loggedin']))
{
die("you are not loggeddin");
}
echo "Welcome {$_SESSION['name']}";
?>
<?php
session_start();
mysql_connect("localhost","root","") or die(mysql_error);
mysql_select_db("tutorial") or die("could not select database");
if(isset($_SESSION['loggedin']))
{
echo "you are already loggeddin";
}
if(isset($_POST['submit']))
{
$name=$_POST['username'];
$pass=$_POST['password'];
$res="select * from users where name='$name' and password='$pass'";
$result=mysql_query($res);
if(mysql_num_rows($result) < 1)
{
die("Password incorrect try again !");
}
$_SESSION['loggedin']= "YES";
$_SESSION['name']=$name;
die("Login Successful");
}
echo "
<form name='frm' method='POST'>
Username : <input type='text' name='username'> <br>
Password : <input type='text' name='password'><br>
<input type='submit' name='submit' value='submit'>";
?>
-----------------------
logout
<?php
session_start();
session_destroy();
header("location:login.php");
?>-------------------------
chk session
<?php
session_start();
if(!isset($_SESSION['loggedin']))
{
die("you are not loggeddin");
}
echo "Welcome {$_SESSION['name']}";
?>
---------------
logoff.html
<html>
<a href="./logout.php">Logout</a>
</html>
No comments: