加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php使用cookie实现记住用户名和密码实现代码

发布时间:2020-12-13 02:35:27 所属栏目:PHP教程 来源:网络整理
导读:《:php使用cookie实现记住用户名和密码实现代码》要点: 本文介绍了:php使用cookie实现记住用户名和密码实现代码,希望对您有用。如果有疑问,可以联系我们。 PHP应用 meta http-equiv="Content-Type" content="text/html; charset=utf-8" /form id="form1

《:php使用cookie实现记住用户名和密码实现代码》要点:
本文介绍了:php使用cookie实现记住用户名和密码实现代码,希望对您有用。如果有疑问,可以联系我们。

PHP应用
<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['name'];?>" name="name"></td>
 </tr>
 <tr align="center">
 <td>密码:</td>
 <td><input type="password" name="password" value="<?php echo $_COOKIE['password']?>"></td>
 </tr>
 <tr align="center">
 <td>记住用户名和密码</td>
 <td><?php if($_COOKIE['remember'] == 1){?><input type="checkbox" name="remember" value="1" checked><?php }else{($_COOKIE['remember'] == "")?><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['name'];
 $password = $_POST['password'];
 $remember = $_POST['remember'];
 if($remember == 1){
 setcookie('name',$name,time()+3600);
 setcookie('password',$password,time()+3600);
 setcookie('remember',$remember,time()+3600);
 }else{
 setcookie('name',time()-3600);
 setcookie('password',time()-3600);
 setcookie('remember',time()-3600);
 }
 echo "<a href="remember.php">返回</a>";
?>

欢迎参与《:php使用cookie实现记住用户名和密码实现代码》讨论,分享您的想法,编程之家 52php.cn为您提供专业教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读