创建脚本文件 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了就没有下载一次了哦。