From 79146b2435747d55effda9644486ca1dd816ce72 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Thu, 17 Nov 2011 01:38:40 +0100 Subject: [PATCH] Pokus o opraveni logoutu --- lib/HTTP_Auth.class.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/HTTP_Auth.class.php b/lib/HTTP_Auth.class.php index f1f0f6e..f03086e 100755 --- a/lib/HTTP_Auth.class.php +++ b/lib/HTTP_Auth.class.php @@ -42,6 +42,11 @@ class HTTP_Auth { Header('HTTP/1.0 401 Unauthorized'); } + function get_current_url($login='logout@') { + $proto = empty($_SERVER['HTTPS']) ? $proto = 'http' : $proto = 'https'; + return $proto.'://'.$login.$_SERVER['HTTP_HOST'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF']; + } + static function check_auth_internal($user, $pass) { //Check if login is succesfull //(U can modify this to use DB, or anything else) return (isset($GLOBALS['users'][$user]) && ($GLOBALS['users'][$user] == $pass)); @@ -65,15 +70,8 @@ class HTTP_Auth { //Logout if(isset($_GET['logout'])) { //script.php?logout - if(isset($PHP_AUTH_USER) || isset($PHP_AUTH_PW)) { - Header('WWW-Authenticate: Basic realm="'.$realm.'"'); - Header('HTTP/1.0 401 Unauthorized'); - } else { - $location=$this->location; - if($_GET['logout'] != '') $location = $_GET['logout']; - if(trim($location) != '401') Header('Location: '.$location); - die("$this->cbanner401 - Log out successfull\n

401 - Log out successfull

\nContinue...\n$this->hbanner"); - } + Header('HTTP/1.0 302 Found'); + Header('Location: '.$this->get_current_url()); } if(!isset($PHP_AUTH_USER)) { @@ -94,10 +92,8 @@ class HTTP_Auth { } function __construct($realm='private', $require_login=true, $auth_function=false) { - //Misc - $this->location = '401'; //Location after logout - 401 = default logout page (can be overridden by ?logout=[LOCATION]) //CopyLeft - $ver = '2o1o-4.0'; + $ver = '2o11-5.0'; $link = 'blog.harvie.cz'; $banner = "Harvie's PHP HTTP-Auth script (v$ver)"; $this->hbanner = "
$banner\n-\n$link\n"; -- 2.30.2