hhheng
Jul 19th 2008, 12:56 am
Login script:session_start();
$admuserS = $_SESSION[user];
$admuserC = $_COOKIE[user];
$admuser = $admuserc? $admuserS : ($admuserC? $admuserC : false);
$loggedin = 0;
$msg = "";
if(!$admuser AND $_POST){
if($_POST[user]==$username && $_POST[pass]==$password){
$_SESSION[user] = $_POST[user];
setcookie("user", $_POST[user], time()+7200, "/", str_replace(".", "", $_SERVER[HTTP_SERVER_NAME]));
$loggedin = 1;
}else{
$msg = "Wrong username or password<hr>";
}
}
Logout Script:session_start ();
$_SESSION = array ();
if (isset ($_COOKIE[session_name ()]))
setcookie (session_name (), '', time () - 42000, '/');
@ session_write_close ();
@ session_unset ();
@ session_destroy ();//Fix IE Bug
@ header ('Location: ../index.php');
exit();
Problem with the above script:
If I put the login script in the header for several files, login any file and then launch other files will not require the login again, it will go straight to the logged in page.
By just clicking logout, it will log out, but if you type in the url again, it will still go straight to the logged in page without requiring logging username and password.
The page will be only expired until reach the 7200 time limit.
While in the logged in pages, if we close the browser or turned to outside pages, and then type in the url for the pages again, they will not require logging username and password.
What i want is by clicking logout and then will require logging username and password to go back to the page, and while in the logged in page, if we close the browser, or turned to other page, and then come back again, will require logging username and password again.
$admuserS = $_SESSION[user];
$admuserC = $_COOKIE[user];
$admuser = $admuserc? $admuserS : ($admuserC? $admuserC : false);
$loggedin = 0;
$msg = "";
if(!$admuser AND $_POST){
if($_POST[user]==$username && $_POST[pass]==$password){
$_SESSION[user] = $_POST[user];
setcookie("user", $_POST[user], time()+7200, "/", str_replace(".", "", $_SERVER[HTTP_SERVER_NAME]));
$loggedin = 1;
}else{
$msg = "Wrong username or password<hr>";
}
}
Logout Script:session_start ();
$_SESSION = array ();
if (isset ($_COOKIE[session_name ()]))
setcookie (session_name (), '', time () - 42000, '/');
@ session_write_close ();
@ session_unset ();
@ session_destroy ();//Fix IE Bug
@ header ('Location: ../index.php');
exit();
Problem with the above script:
If I put the login script in the header for several files, login any file and then launch other files will not require the login again, it will go straight to the logged in page.
By just clicking logout, it will log out, but if you type in the url again, it will still go straight to the logged in page without requiring logging username and password.
The page will be only expired until reach the 7200 time limit.
While in the logged in pages, if we close the browser or turned to outside pages, and then type in the url for the pages again, they will not require logging username and password.
What i want is by clicking logout and then will require logging username and password to go back to the page, and while in the logged in page, if we close the browser, or turned to other page, and then come back again, will require logging username and password again.