cookie login
<?php
$con = mysqli_connect("localhost","root","root","cookielogin") or die(mysqli_error($con));
session_start();
if(isset($_POST['btn_login']))
{
extract($_POST);
$query=mysqli_query($con,"select * from login where username='$username' and password='$password'" ) or die(mysqli_error($con));
$row=mysqli_fetch_assoc($query);
if($row)
{
if(!empty($_POST['re'])){
setcookie("username",$_POST['username'],time() + (48*60*60));
setcookie("password",$_POST['password'],time() + (24*60*60));
}
else
{
if(isset($_COOKIE['username']))
{
setcookie("username","");
}
if(isset($_COOKIE['password']))
{
setcookie("password","");
}
}
header("location:welcome.php");
}else
{
$message="Invalid login";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
</head>
<body>
<?php if(isset($message)) { echo $message; }?>
<form method="POST">
Username:<input type="text" name="username" value="<?php if(isset($_COOKIE['username'])) { echo $_COOKIE['username']; }?>"><br><br>
Password:<input type="password" name="password" value=""><br><br>
<input type="checkbox" name="re" <?php if(isset($_COOKIE['username'])) { ?> checked <?php }?> >Remeber Me <br><br><br>
<input type="submit" name="btn_login" value="LOGIN">
</form>
</body>
</html>
$con = mysqli_connect("localhost","root","root","cookielogin") or die(mysqli_error($con));
session_start();
if(isset($_POST['btn_login']))
{
extract($_POST);
$query=mysqli_query($con,"select * from login where username='$username' and password='$password'" ) or die(mysqli_error($con));
$row=mysqli_fetch_assoc($query);
if($row)
{
if(!empty($_POST['re'])){
setcookie("username",$_POST['username'],time() + (48*60*60));
setcookie("password",$_POST['password'],time() + (24*60*60));
}
else
{
if(isset($_COOKIE['username']))
{
setcookie("username","");
}
if(isset($_COOKIE['password']))
{
setcookie("password","");
}
}
header("location:welcome.php");
}else
{
$message="Invalid login";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
</head>
<body>
<?php if(isset($message)) { echo $message; }?>
<form method="POST">
Username:<input type="text" name="username" value="<?php if(isset($_COOKIE['username'])) { echo $_COOKIE['username']; }?>"><br><br>
Password:<input type="password" name="password" value=""><br><br>
<input type="checkbox" name="re" <?php if(isset($_COOKIE['username'])) { ?> checked <?php }?> >Remeber Me <br><br><br>
<input type="submit" name="btn_login" value="LOGIN">
</form>
</body>
</html>
Comments
Post a Comment