PHP uses cookies to implement the function of web pages remembering usernames and passwords

不言
Release: 2023-03-24 22:56:02
Original
2297 people have browsed it

The content of this article is about PHP using cookies to realize the function of remembering user names and passwords on web pages. It has a certain reference value. Now I share it with you. Friends in need can refer to it

1. html part

<!doctype html>
<html class="no-js">
<head>
  <title>记住账号密码</title>
  <style type="text/css">
      </style>
      </head>
      <body>
<form method="post" action="<{url  c=$mc a=&#39;remtest&#39;}>">
<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>
Copy after login
2.php部分
Copy after login
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;
}
Copy after login

Related recommendations:

PHP uses file_get_contents to send http requests


The above is the detailed content of PHP uses cookies to implement the function of web pages remembering usernames and passwords. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template