In this article going to discuss login and logout using php .The first read previous article  https://blog.pheonixsolutions.com/basic-insert-delete-update-database-image-upload-using-php/.

LOGIN.PHP

$query=mysql_connect("localhost","root","");
mysql_select_db("demo",$query);
session_start();
if(isset($_POST['send']))
{
$name=$_POST['name'];
$password=$_POST['password'];
if($name!="" && $password!="")
{ 
$s=mysql_query("select *from reg where name = '$name' AND password = '$password'");
$a=mysql_fetch_array($s);
$count=mysql_num_rows($s);
if($count==0)
{
echo "user does not exist";
}
else
{
$_SESSION['name']=$a['name'];
header("location:indedx.php");
}
}
}
<!DOCTYPE html>
<html>
<head>
 <title></title>
</head>
<body>
<form action="" method="post">
<table width="400" border="0" cellspacing="0" cellpadding="0" >
 <tr>
 <td>username</td>
 <td>:</td>
 <td><input type="text" name="name" /></td>
 
 </tr>
 <tr>
 <td>password</td>
 <td>:</td>
 <td><input type="password" name="password" /></td>
 </tr>
 <tr>
 <td><input type="submit" name="send" /></td>
 </tr>
</table>
</form>
</body>
</html>

LOGOUT.PHP

<?php 
session_start();
session_destroy();
header("location:login.php");
?>

 

Leave a Reply