-1
這種形式不提交,但我試圖讓它重定向到一個頁面,如果密碼是正確的,如果沒有,然後轉到主頁。我也試圖記住我的Cookie功能。一點幫助,將不勝感激。PHP登錄表格無數據庫
代碼:
<?php
if($logged_in){header('Location: index.php');}
function checkLogin(){
/* Check if user has been remembered */
if(isset($_COOKIE['cookpass'])){
$_SESSION['password'] = $_COOKIE['cookpass'];
}
/* Username and password have been set */
if(isset($_SESSION['password'])){
/* Confirm that username and password are valid */
if($_SESSION['password'] != 'password'){
/* Variables are incorrect, user not logged in */
unset($_SESSION['password']);
return false;
}
return true;
}
/* User not logged in */
else{
return false;
}
}
if(isset($_POST['sublogin'])){
//Set Variables
$password = $_POST['password'];
if($password == 'password'){
$md5pass = md5($password);
$_SESSION['password'] = $md5pass;
if(isset($_POST['remember'])){
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
}
}
}
echo 'Not Logged In';
$logged_in = checkLogin();
?>
形式:
<form id="form1" name="form1" method="post" action="">
Password: <input name="password" type="password" /><br/><br/>
Remember Me: <input type="checkbox" name="remember" id="remember" />
<input name="sublogin" type="submit" value="Login" style="float:right;" />
<br/>
<p></p>
</form>
如果我想將它保留在一頁上,我將如何做php自我 – user1345650