修改的PHP登入程式,關閉瀏覽器session清空,可以設定cookies時間
阿新 • • 發佈:2019-02-13
<FORM ACTION="checklogin.php" METHOD="POST">
<TABLE height=159 cellSpacing=0 cellPadding=0 width=268 align=center
bgColor=#ffff99 border=0>
<TBODY>
<TR>
<TD align=middle width=234 height=43><IMG height=113
src="images/login.gif" width=359></TD></TR>
<TR>
<TD align=middle background=images/loginbg.gif
bgColor=#fafafa height=180>
<TABLE width=250 border=0>
<TBODY>
<TR>
<TD align=middle height=25>帳號: <INPUT tabIndex=1
maxLength=20 size=15 name=username></TD></TR>
<TR>
<TD align=middle>密碼: <INPUT tabIndex=2
type=password maxLength=20 size=15 name=password></TD></TR>
<TR>
<TD align=middle height=25><INPUT id=login_manager style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND-IMAGE: url(images/loginbutton.gif); BORDER-LEFT: 0px; WIDTH: 52px; CURSOR: hand; BORDER-BOTTOM: 0px; HEIGHT: 18px" type=submit value=" " name=login_manager>
<INPUT id=login_member2 style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND-IMAGE: url(images/loginbutton2.gif); BORDER-LEFT: 0px; WIDTH: 52px; CURSOR: hand; BORDER-BOTTOM: 0px; HEIGHT: 18px" type=reset value=" " name=login_member2></TD></TR>
<TR>
<TD align=middle>
<TABLE border=0>
<TBODY>
<TR>
<TD></TD>
<TD width=10></TD>
<TD></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=middle background=images/loginend.gif
height=5></TD></TR></TBODY></TABLE></FORM>
這個頁面就是一個登入表單
檢查是否登入
checklogin.php
<?php require_once('../Connections/lr.php'); ?>
<?php
// 表單提交後...
$username = trim($_REQUEST['username']);
$password = trim($_REQUEST['password']);
mysql_select_db($database_lr, $lr);
$sql = "SELECT username, password FROM admin WHERE username='$username' AND password='$password'";
// 取得查詢結果
$result = mysql_query( $sql );
$userInfo = @mysql_fetch_array($result);
if (!empty($userInfo)) {
if ($userInfo["username"] == $username) {
// 當驗證通過後,啟動 Session
session_start();
echo("<meta http-equiv=refresh content='0; url=index.php'>");
// 註冊登陸成功的 admin 變數,並賦值 true
$_SESSION["admin"] = true;
} else {
die("使用者名稱密碼錯誤");
}
} else {
die("使用者名稱密碼錯誤");
}
?>
這裡可以讓錯誤的轉到再次登入頁面
<TABLE height=159 cellSpacing=0 cellPadding=0 width=268 align=center
bgColor=#ffff99 border=0>
<TBODY>
<TR>
<TD align=middle width=234 height=43><IMG height=113
src="images/login.gif" width=359></TD></TR>
<TR>
<TD align=middle background=images/loginbg.gif
bgColor=#fafafa height=180>
<TABLE width=250 border=0>
<TBODY>
<TR>
<TD align=middle height=25>帳號: <INPUT tabIndex=1
maxLength=20 size=15 name=username></TD></TR>
<TR>
<TD align=middle>密碼: <INPUT tabIndex=2
type=password maxLength=20 size=15 name=password></TD></TR>
<TR>
<TD align=middle height=25><INPUT id=login_manager style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND-IMAGE: url(images/loginbutton.gif); BORDER-LEFT: 0px; WIDTH: 52px; CURSOR: hand; BORDER-BOTTOM: 0px; HEIGHT: 18px" type=submit value=" " name=login_manager>
<INPUT id=login_member2 style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND-IMAGE: url(images/loginbutton2.gif); BORDER-LEFT: 0px; WIDTH: 52px; CURSOR: hand; BORDER-BOTTOM: 0px; HEIGHT: 18px" type=reset value=" " name=login_member2></TD></TR>
<TR>
<TD align=middle>
<TABLE border=0>
<TBODY>
<TR>
<TD></TD>
<TD width=10></TD>
<TD></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=middle background=images/loginend.gif
height=5></TD></TR></TBODY></TABLE></FORM>
這個頁面就是一個登入表單
檢查是否登入
checklogin.php
<?php require_once('../Connections/lr.php'); ?>
<?php
// 表單提交後...
$username = trim($_REQUEST['username']);
$password = trim($_REQUEST['password']);
mysql_select_db($database_lr, $lr);
$sql = "SELECT username, password FROM admin WHERE username='$username' AND password='$password'";
// 取得查詢結果
$result = mysql_query( $sql );
$userInfo = @mysql_fetch_array($result);
if (!empty($userInfo)) {
if ($userInfo["username"] == $username) {
// 當驗證通過後,啟動 Session
session_start();
echo("<meta http-equiv=refresh content='0; url=index.php'>");
// 註冊登陸成功的 admin 變數,並賦值 true
$_SESSION["admin"] = true;
} else {
die("使用者名稱密碼錯誤");
}
} else {
die("使用者名稱密碼錯誤");
}
?>
這裡可以讓錯誤的轉到再次登入頁面