newbie php authentication quest.

From: Date: Thu, 15 Mar 2001 10:28:33 +0000
Subject: newbie php authentication quest.
Groups: php.general 
Request: Send a blank email to php-general+get-44006@lists.php.net to get a copy of this message
hi i want to protect a page (lets say its name is test.php) with authentication. therefore i included auth.php as follows: test.php: <?php include "mysql.inc.php"; //open database link include "auth.php"; authentication(); .....?> this is auth.php: <?php function authentication() { if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic realm=\"test Realm\""); Header("HTTP/1.0 401 Unauthorized"); echo "you canceled the authentication, access denied\n"; exit; } else { $query="select * from users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; $result = mysql_query($query,$link); $num = mysql_numrows($result); if($num==1) { return; } else { echo "wrong user or password"; exit; } } } ?> the problem is that when i want to open test.php i get the authentication box, then i enter username and password and then i get again this box. i can enter the user and passwd 3 times, then i get the error message "you canceled the authentication" form my auth.php function. but when i copy the source code from auth.php to a new file without as function {} and substitute the return with echo "hi"; it works. has anyone an idea. thanks chris

« previous php.general (#44006) next »