note 13575 added to features.http-auth.php

From: Date: Fri, 22 Jun 2001 11:06:24 +0000
Subject: note 13575 added to features.http-auth.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14555@lists.php.net to get a copy of this message
I've used the small script from tigran@freenet.am posted 19-May-2000 02:31, it's pretty fine, authetification and logout using headers, but I've found a small error: The login on the database must be set to 0 when the user is not authorized because if you click "cancel" on the password dialog the browser (at least IE5.5) thinks that the previous user is entering and sets both $PHP_AUTH_USER and $PHP_AUTH_PW to the old values, and the next time you try to enter it doesn't ask for authentification Using the same code as him/her the function auth() will be: function auth () { global $PHP_AUTH_USER, $PHP_AUTH_PW; Header("WWW-Authenticate: Basic realm=\"ArmFN public site\""); Header("HTTP/1.0 401 Unauthorized"); mysql_connect("localhost","train","") or die("Unable to connect to SQL server"); mysql_select_db( "train") or die( "Unable to select database"); mysql_query("update users set login=0 where id='$PHP_AUTH_USER' and pasw='$PHP_AUTH_PW'") or die("k"); echo "You have to authentificate yourself first \n"; exit; } http://www.php.net/manual/en/features.http-auth.php

« previous php.notes (#14555) next »