<?php
include("config.php");
session_start();
/*--------------------刪除cookies記錄,讓cookies過期-----------------------------------*/
if($_GET["del"]=="cookies")
{
setcookie("usercookies", "", time()-3600);
setcookie("pwdcookies", "", time()-3600);
echo "<SCRIPT type=text/javascript>
var n = 5;
var timer = setInterval(function() {
n--;
document.getElementById('second').innerHTML = n;
if (n == 0) {
clearInterval(timer);
window.location = 'login.php';
}
}, 1000);
</SCRIPT>刪除成功<br><B class='chengse STYLE1' id=second>5</B>秒後回到首頁";
exit();
}
/*------------------------如果判斷已經有cookies存在,則進行自動登錄操作----------------------------------*/
if($_COOKIE["usercookies"]!="" and $_COOKIE["pwdcookies"]!="")
{
$username=$_POST["username"];
$userpassword=$_POST["userpassword"];
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
$rs=mysql_fetch_array($sql);
echo"自動跳轉成功";
//exit();
}
/*----------------------------點擊登錄按鈕後的動作act=login----------------------------------*/
if($_GET["act"]=="login")
{
/*------------------判斷獲取的驗證碼是否壹致-------------------------*/
/*if(strtoupper($_SESSION["vcode"])!=strtoupper($_POST["Code"]))
{
echo("<script type='text/javascript'> alert('對不起,驗證碼錯誤!');location.href='javascript:onclick=history.go(-1)';</script>");
exit();
}*/
/*------------------------點擊登錄按鈕後如果判斷已經有cookies存在,則進行自動登錄操作----------------------------------*/
if($_COOKIE["usercookies"]!="" and $_COOKIE["pwdcookies"]!="")
{
$username=$_POST["username"];
$userpassword=$_POST["userpassword"];
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
$rs=mysql_fetch_array($sql);
if($_POST["username"]==$rs["username"] and $_POST["userpassword"]==$rs["userpassword"])
{
echo"<script type='text/javascript'> alert('存在cookies登錄跳轉成功!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
else
{
echo"<script type='text/javascript'> alert('存在cookies登錄跳轉失敗!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
exit();
}
/*-------------------點擊登錄後判斷cookies不存在則進行登錄比較用戶名密碼------------------------------*/
$username=$_POST["username"];
$userpassword=md5($_POST["userpassword"]);
$sql=mysql_query("select * from user where username='$username' and userpassword='$userpassword'");
if($rs=mysql_fetch_array($sql))
{
/*---------------------用戶名密碼判斷正確,寫入cookies動作,同時進行跳轉------------------------------------*/
setcookie("usercookies", $_POST["username"], time()+3600*48);
setcookie("pwdcookies", md5($_POST["userpassword"]), time()+3600*24);
header('Location: /');
exit();
}
else
{
/*-------------------判斷用戶名密碼錯誤,彈出錯誤提示---------------------------*/
echo "<script type='text/javascript'> alert('用戶名或密碼錯誤,請重新輸入!');location.href='javascript:onclick=history.go(-1)';</script>";
exit();
}
}
/*
$user_IP = $_SERVER["REMOTE_ADDR"];//獲取訪問者IP
$file_name=date('Y-m-d').'.txt';//以當前的日期建立txt文件
$file=fopen($file_name,"a+");//如果存在該文件就打開,如果不存在就創建
fwrite($file,$user_IP.'--'.date('Y-m-d H:i:s')."\r\n");//將訪問者IP及當前時刻寫到文件最後,\r\n在文檔最後換行
fclose($file);//關閉文件
*/
><!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>COOKIES判斷是否自動登錄</title>
</head>
<body>
<form action="?act=login" method="post">
<input name="username" type="text" id="username" value="<?php if($_COOKIE["usercookies"]!=""){echo $_COOKIE["usercookies"];}?>" />
<input name="userpassword" type="password" id="userpassword" value="<?php if($_COOKIE["pwdcookies"]!=""){echo $_COOKIE["pwdcookies"];}?>"/>
<!--<img src="yanzhengma_class.php" title="看不清楚?請點擊刷新驗證碼" onClick="this.src='yanzhengma_class.php?t='+(new Date().getTime());" height="20px;"><input name="Code" type="text" id="Code" value="" />-->
<input name="" type="submit" />
</form>
<a href="?del=cookies">刪除cookies</a>
</body>
</html>