Home  >  Article  >  Backend Development  >  PHP records user name and password based on cookies

PHP records user name and password based on cookies

墨辰丷
墨辰丷Original
2018-06-11 13:59:061678browse

This article mainly introduces how PHP records user names and passwords based on cookies. Interested friends can refer to it. I hope it will be helpful to everyone.

The details are as follows:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form id="form1" name="form1" method="post" action="check_remember.php">
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
<thead>
 <tr> 
 <td colspan="2" align="center"><b>记住用户名和密码</b></td> 
 </tr>
</thead> 
 <tr align="center">
 <td>用 户 名:</td>
 <td><input type="text" value="<?php echo $_COOKIE[&#39;name&#39;];?>" name="name"></td>
 </tr>
 <tr align="center">
 <td>密码:</td>
 <td><input type="password" name="password" value="<?php echo $_COOKIE[&#39;password&#39;]?>"></td>
 </tr>
 <tr align="center">
 <td>记住用户名和密码</td>
 <td><?php if($_COOKIE[&#39;remember&#39;] == 1){?><input type="checkbox" name="remember" value="1" checked><?php }else{($_COOKIE[&#39;remember&#39;] == "")?><input type="checkbox" name="remember" value="1"><?php }?></td>
 </tr>
 <tr align="center">
 <td colspan="2"><input type="submit" name="Submit" value="提交" /></td>
 </tr>
</table>
</form>
 
check_remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
 $name = $_POST[&#39;name&#39;];
 $password = $_POST[&#39;password&#39;];
 $remember = $_POST[&#39;remember&#39;];
 if($remember == 1){
 setcookie(&#39;name&#39;,$name,time()+3600);
 setcookie(&#39;password&#39;,$password,time()+3600);
 setcookie(&#39;remember&#39;,$remember,time()+3600);
 }else{
 setcookie(&#39;name&#39;,$name,time()-3600);
 setcookie(&#39;password&#39;,$password,time()-3600);
 setcookie(&#39;remember&#39;,$remember,time()-3600);
 }
 echo "<a href=\"remember.php\">返回</a>";
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

RelatedRecommendation:

The concept and characteristics of PHP singleton mode

## The role and use of type hints in PHP

PHP uses Ajax to connect to Baidu to realize the function of detecting whether the website is connected to the Internet

The above is the detailed content of PHP records user name and password based on cookies. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn