首頁  >  文章  >  後端開發  >  php基於cookie的登入表單(記錄最後登入時間)

php基於cookie的登入表單(記錄最後登入時間)

不言
不言原創
2018-05-19 15:34:282059瀏覽


本文介紹下,基於cookie實作的一個php登入表單,且可以記錄下最後的登入時間,有需要的朋友參考下。
本文介绍下,基于cookie实现的一个php登录表单,且可以记录下最后的登录时间,有需要的朋友参考下。

一个基于cookie原理实现的登录表单。

代码:

<html>
  <head>
  <title>用户登录表单</title>
  </head>
  <body>
  <form name="forml" method="POST" action="CookieBasedPasswordLogin.php">
    <table>
      <tr>
       <td colspan="2" >
         <p align="center"><b>请输入用户名与密码</b></p>
       </td>
     </tr>
   <tr>>
     <td>
       <p align="right">Customer ID</p>
     </td>
     <td>
       <input type="text" name="username">
     </td>
   </tr>
   <tr>
     <td>
       <p align="right">Password</p>
     </td>
     <td>
       <input type="password" name="password">
     </td>
   </tr>
   <tr>
     <td colspan="2">
       <center>
         <input type="submit" name="Submit" value="Login">
       </center>
     </td>
    </tr>
   </table>
  </form>
  </body>
  </html>
  
<!-- CookieBasedPasswordLogin.php
<?php
//检测用户登录
//基于cookie实现的用户登录检测程序
//edit by www.jbxue.com
    $now = getdate();
    $storetime= $now["weekday"] . " " . $now["month"] ." " . $now["year"] ;
    $storetime.=" Time : ";

    if ($now["hours"] < 10) {
      $storetime.= "0" . $now["hours"];
    } else {
      $storetime.= $now["hours"];
    }
  
    $storetime.= ":";
    if ($now["minutes"]<10) {
      $storetime.= "0" . $now["minutes"];
    } else {
      $storetime.= $now["minutes"];
    }
    
    $storetime.= ": ";
    if ($now["seconds"] <10) {
      $storetime.= "0" . $now["seconds"];
    } else {
      $storetime.= $now["seconds"];
    }
    if (isset($data)) {
       $counter=++$data[l];
        setcookie("data[0]",$storetime,time() + (60*60*24));
        setcookie("data[l]", $counter,time() + (60*60*24)); setcookie("data[2]",$username,time() + (60*60*24));
        echo "<b><center>Hi " . $data[2] . " ! !</center></b><br>n";
        echo "<b><center>Last Login Time :" .$data[0] . "</center></b><br>n";
        echo "<b><center>Current Date :" .$storetime. "</center></b><br>n";
        echo "<b><center>Page View Count :" . $data[l]. "</center></b><br>n";
        echo "<b><center>成功登录!</center></b>";
        echo ("<b><contor>您可以在24小时内,无需再次登录,即可访问本站的内容。</center></b>");
   } else {
    if (isset($username) && isset($password)) {
     if ($password=="superpass") {
          $counter=0;
          setcookie("data[0]",$storetime,time() + (60*60*24));
          setcookie("data[l]",$counter,time() + (60*60*24));
          setcookie("data[2]",$username,time() + (60*60*24));
          $url="Location: cookieimp.php";
          header($url);
     }else{
          echo "<hl><center>密码无效!</center></hl>";
     }
    }
  }
  ?>  
-->

一個基於cookie原理實現的登入表單。


代碼:

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn