>  기사  >  백엔드 개발  >  php使用cookie实现记住用户名和密码实现代码,phpcookie_PHP教程

php使用cookie实现记住用户名和密码实现代码,phpcookie_PHP教程

WBOY
WBOY원래의
2016-07-13 09:56:08862검색

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

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/990542.htmlTechArticlephp使用cookie实现记住用户名和密码实现代码,phpcookie meta http-equiv="Content-Type" content="text/html; charset=utf-8" /form id="form1" name="form1" method="post"...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.