萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php使用cookie實現記住用戶名和密碼實現代碼

php使用cookie實現記住用戶名和密碼實現代碼

   這篇文章主要介紹了php使用cookie實現記住用戶名和密碼實現代碼,本文直接給出實現代碼,需要的朋友可以參考下

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 <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',$name,time()-3600); setcookie('password',$password,time()-3600); setcookie('remember',$remember,time()-3600); } echo "<a href="remember.php">返回</a>"; ?>
copyright © 萬盛學電腦網 all rights reserved