1. 程式人生 > >php 利用cookie實現網頁記住使用者名稱和密碼的功能()

php 利用cookie實現網頁記住使用者名稱和密碼的功能()

1.html部分

<!doctype html>
<html class="no-js">
<head>
  <title>記住賬號密碼</title>
<style type="text/css">
 </style>
</head>
<body>
<formmethod="post" action="<{url  c=$mc a='remtest'}>">
<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="<{$name}>" name="name"></td> </tr>
<tr align="center"> <td>密碼:</td> <td><input type="text" name="password" value="<{$password}>"></td> </tr> <tr align="center"> <td>記住使用者名稱和密碼</td> <td> <{if $remember ==3}> <input type="radio" name="remember"
value="3" checked><input type="radio" name="remember" value="2"><{else}> <input type="radio" name="remember" value="3"><input type="radio" name="remember" value="2" checked><{/if}> </td> </tr> <tr align="center"> <td colspan="2"><input type="submit" name="Submit" value="提交" /></td> </tr> </table> </form> </body> </html>
2.php部分
function actionRemember(){
$this->name=$_COOKIE['name'];
$this->password=$_COOKIE['password'];
$this->remember=$_COOKIE['remember'];
$this->display("$this->subpath/remember.html");
}
function actionRemtest(){
$remember=$_POST['remember'];
$name=$_POST['name'];
$password=$_POST['password'];
if($remember == '3'){
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);
}
exit;
}