Home >>Advance PHP Tutorial >PHP Remember me

PHP Remember me

PHP Remember me Cookie

As the name indicate the meaning that cookies are the method to store the information of a web page in a remote browser,those information can be retrieved form the browser itself,when the same user comes back to that page.

The browser stores the message in a small text file that the server embeds on the user's system.

You can set cookies using the setcookie()function. PHP transparently supports HTTP cookies,so setcookie() must be called before any output is sent to the browser.

The main purpose of cookies is to identify users and possibly prepare customized Web pages for them.

Login Page PHP Script(Static Login page where [email protected] and pass=123)

<?php
@$id=$_POST['id'];       
@$pass=$_POST['pass'];
if(isset($_POST['signin']))	
{		
if($id=="[email protected]" && $pass==123)		
{			
if($_POST['ch']==true)			
{			
setcookie("cid",$id,time()+60*60);			
setcookie("cpass",$pass,time()+60*60);			
header('location:https://www.phptpoint.com');			
}			
header('location:https://www.phptpoint.com');		
}		
else		
{		
echo "invalid id or pass";		
}	
}    
?>

Create Login Form(HTML Script)

<html>
<form method="post"> 
<table align="center"> 	
<tr>		
<td colspan="2" align="center"><?php echo @$err;?></td>	
</tr>		
<tr>		
<th>Your email</th>		
<td><input type="email" name="id" placeholder="[email protected]"  value="<?php echo @$_COOKIE['cid'];?>" required/></td>	
</tr>	
<tr>		
<th>Your password</th>		
<td><input type="password" placeholder="123" name="pass" value="<?php echo @$_COOKIE['cpass'];?>" required/></td>	
</tr>	
<tr>		
<th>stay signed in</th>		
<td><input type="checkbox" name="ch"/></td>	
</tr>	
<tr>	
<td colspan="2" align="center">		
<input type="submit" name="signin" value="SignIn"/></td>	
</tr>
</table>	
</body>
</form>
</html>
Output :Cookies Remember me

No Sidebar ads