Enabling remember me on signin page using php cookies

In this application, we use PHP cookes to enable “remember me” option

<?php session_start(); ?>
<html>
<head>
<?php
//print_r($_COOKIE);

/*
if(strlen($_COOKIE['userid'])!=0)
{
$_SESSION['isloggedin'] = true;		
echo "<script language='javascript'>window.location.href='default.php';</script>";	
}
*/

$userid = isset($_COOKIE['userid'])?$_COOKIE['userid']:"";
$passwd = isset($_COOKIE['passwd'])?$_COOKIE['passwd']:"";

if (isset($_POST['btnsubmit']) )
{
//setcookie("count",500);
$username = $_POST['txtname'];
$password = $_POST['txtpassword'];
$remember = isset($_POST['chkremember'])?$_POST['chkremember']:"";



if($username == "ali" && $password == "123")
{
$_SESSION['isloggedin'] = true;	

if( strlen($remember)!=0 )
{
  setcookie("userid",$username, time()+3600);
  setcookie("passwd",$password, time()+3600);
}

//header('Location: default.php');
echo "<script language='javascript'>window.location.href='default.php';</script>";
}
else
{
  echo "Wrong username/password";
}
 
}

if( isset($_POST['btnread']) )
{
//print_r($_COOKIE);	
echo $_COOKIE['count'];
}


?>
</head>
<body>
<form name="form1" method="post" action="">
Username:   <input type="text" name="txtname" id="txtname" value="<?php echo $userid; ?>" >
  <br>
 Password:  <input id="txtpassword" name="txtpassword" type="password" value="<?php echo $passwd; ?>" />
  <input type="submit" name="btnsubmit" id="btnsubmit" value="Login">
  <br>
  Remember: <input id="chkremember"  name="chkremember" type="checkbox" value="remember" />
</form>
</body>
</html>

 

 

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *