note 88957 added to features.http-auth

From: Date: Sun, 15 Feb 2009 14:11:44 +0000
Subject: note 88957 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-150699@lists.php.net to get a copy of this message
Good day. Sorry for my english. This example shows programming "LOGIN", "LOGOUT" and "RE-LOGIN". This script must use in the protected pages. For work this script the browser address string must be following: "http://localhost/admin/?login" - for Login, "http://localhost/admin/?logout" - for Logout, "http://localhost/admin/?logout&login" - for Re-Login. <?php session_start(); $authorized = false; # LOGOUT if (isset($_GET['logout']) && !isset($_GET["login"]) && isset($_SESSION['auth'])) { $_SESSION = array(); unset($_COOKIE[session_name()]); session_destroy(); echo "logging out..."; } # checkup login and password if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $user = 'test'; $pass = 'test'; if (($user == $_SERVER['PHP_AUTH_USER']) && ($pass == ($_SERVER['PHP_AUTH_PW'])) && isset($_SESSION['auth'])) { $authorized = true; } } # login if (isset($_GET["login"]) && !$authorized || # relogin isset($_GET["login"]) && isset($_GET["logout"]) && !isset($_SESSION['reauth'])) { header('WWW-Authenticate: Basic Realm="Login please"'); header('HTTP/1.0 401 Unauthorized'); $_SESSION['auth'] = true; $_SESSION['reauth'] = true; echo "Login now or forever hold your clicks..."; exit; } $_SESSION['reauth'] = null; ?> <h1>you have <? echo ($authorized) ? (isset($_GET["login"]) && isset($_GET["logout"]) ? 're' : '') : 'not '; ?>logged!</h1> ---- Server IP: 69.147.83.197 Probable Submitter: 84.42.63.166 ---- Manual Page -- http://www.php.net/manual/en/features.http-auth.php Edit -- https://master.php.net/note/edit/88957 Del: integrated -- https://master.php.net/note/delete/88957/integrated Del: useless -- https://master.php.net/note/delete/88957/useless Del: bad code -- https://master.php.net/note/delete/88957/bad+code Del: spam -- https://master.php.net/note/delete/88957/spam Del: non-english -- https://master.php.net/note/delete/88957/non-english Del: in docs -- https://master.php.net/note/delete/88957/in+docs Del: other reasons-- https://master.php.net/note/delete/88957 Reject -- https://master.php.net/note/reject/88957 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150699) next »