php实例之基于Cookie的登录表单和获取最后登录时间

发布时间:2020-11-11编辑:脚本学堂
php实现一个基于cookie的登录表单,并可以取得最后的登录时间的一例代码,有需要的朋友作个参考吧。

1,html部分

<html>
  <head>
  <title>基于cookie的登录表单,密码提交页-www.jb200.com</title>
  </head>
  <body>
  <form name="forml" method="POST"
  action="CookieBasedPasswordLogin.php">
    <table>
      <tr>
       <td colspan="2" >
         <div align="center"><b>请输入您的密码</b></div>
       </td>
     </tr>
   <tr>>
     <td>
       <div align="right">用户名:</div>
     </td>
     <td>
       <input type="text" name="username">
     </td>
   </tr>
   <tr>
     <td>
       <div align="right">密 码:</div>
     </td>
     <td>
       <input type="password" name="password">
     </td>
   </tr>
   <tr>
     <td colspan="2">
       <center>
         <input type="submit" name="Submit" value="登 录">
       </center>
     </td>
    </tr>
   </table>
  </form>
  </body>
  </html>

2,登录检测页 CookieBasedPasswordLogin.php

<?php
    $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>最后登录时间 :" .$data[0] .
 "</center></b><br>n";
        echo "<b><center>当前日期 :" .$storetime.
 "</center></b><br>n";
        echo "<b><center>网页浏览记录 :" . $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>";
     }
    }
  }
  ?>
-->