note 87685 added to features.http-auth

From: Date: Tue, 16 Dec 2008 20:02:05 +0000
Subject: note 87685 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-148230@lists.php.net to get a copy of this message
The sample from danja at k0a1a dot net is great for getting started. However, it has some typos. Below is a slightly revised version that should work "out of the box": <?php session_start(); $authorized = false; if(isset($_GET['logout']) && ($_SESSION['auth'])) { $_SESSION['auth'] = null; session_destroy(); echo "logging out..."; } 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'])) && (!empty($_SESSION['auth']))) { $authorized = true; } } if (isset($_GET["login"]) && (! $authorized)) { header('WWW-Authenticate: Basic Realm="Login please"'); header('HTTP/1.0 401 Unauthorized'); $_SESSION['auth'] = true; print('Login now or forever hold your clicks...'); exit; } ?> <h1>you have <? echo ($authorized) ? '' : 'not'; ?> logged!</h1> ---- Server IP: 69.147.83.197 Probable Submitter: 68.159.126.54 ---- Manual Page -- http://www.php.net/manual/en/features.http-auth.php Edit -- https://master.php.net/note/edit/87685 Del: integrated -- https://master.php.net/note/delete/87685/integrated Del: useless -- https://master.php.net/note/delete/87685/useless Del: bad code -- https://master.php.net/note/delete/87685/bad+code Del: spam -- https://master.php.net/note/delete/87685/spam Del: non-english -- https://master.php.net/note/delete/87685/non-english Del: in docs -- https://master.php.net/note/delete/87685/in+docs Del: other reasons-- https://master.php.net/note/delete/87685 Reject -- https://master.php.net/note/reject/87685 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148230) next »