php記錄並顯示使用者上次登入的時間

來源:互聯網
上載者:User

建立指令碼檔案 form_login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>

<title>使用者登入</title>

<link rel='stylesheet' type='text/css' href='style.css'>

<style>

#showTime{

width:291px;

border:1px solid #ccc;

line-height:23px;

position:absolute;

left:500px;

top:48px;

text-align:center;

}

</style>

</head>

<body>


<?php

if(isset($_COOKIE['login_now'])){

echo "<div id='showTime'>";

echo '您上次登入的時間為:'.$_COOKIE['login_now'];

echo "</div>";

}

?>

</div>

<div id="login">

<h2>

<input id="fnquit" type="button" title="退出登入" />

<a href="#" class="cur" name="Email">Email登入</a>

</h2>

<ul>

<form id="myForm" name="myForm" method="post" action='login_time.php'>

<li>

<input id="login_type" name="login_type" type="hidden"/>

<tt>

<label id="log_type" for="email">Email:</label>

</tt>

<div>

<input id="username" name="username" type="text" class="cell" />

</div>

</li>

<li>

<tt>

<label for="password">密 碼:</label>

</tt>

<div>

<input id="password" name="password" type="password" class="cell" />

</div>

</li>

<li>

<div>

<input id="auto_login" name="auto_loginmberme" type="checkbox"/>

<label for="auto_login">下次自動登入</label>

</div>

</li>

<li>

<div>

<input id="sub" type="submit" value=''/><a href="#" target="_blank" >忘記密碼?</a>

</div>

</li>

</form>

</ul>

</div>

</body>

</html>

建立指令碼檔案 login_time.php

<?php

date_default_timezone_set('Asia/Shanghai');//設定時區為東八區

if(!empty($_POST['username'])){

$name = $_POST['username'];

$pwd = $_POST['password'];

if($name = 'admin' && $pwd = 'admin'){

setCookie('login_now',date('Y-m-d H:i:s'),time()+3600*24);

echo "<script>alert('登入成功!');location='login_in.php'</script>";

}else{

echo "<script>alert('登入失敗!');location='login.php'</script>";

}

}

?>

建立指令碼檔案 login_in.php

<?php

echo "使用者登入時間:".$_COOKIE['login_now']."<br>";

echo "<a href='form_login.php'>登出返回</a>";

?>

補充:如果是資料庫會更好一些因為cookie如果使用者把它清除cookie了就沒有下載一次了哦。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.