Re: PHP_AUTH_USER & .htaccess

From: Date: Mon, 12 Mar 2007 08:08:49 +0000
Subject: Re: PHP_AUTH_USER & .htaccess
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-43257@lists.php.net to get a copy of this message
Hello, You can use HTTP_AUTH without .htaccess file. It is very easy. You can use like following example on your web site.:) <?php if ( ( !isset( $_SERVER['PHP_AUTH_USER'] )) || (!isset($_SERVER['PHP_AUTH_PW'])) || ( $_SERVER['PHP_AUTH_USER'] != 'username' ) || ( $_SERVER['PHP_AUTH_PW'] != 'password' ) ) { header( 'WWW-Authenticate: Basic realm="My Private Area"' ); header( 'HTTP/1.0 401 Unauthorized' ); echo "<h1>Authorization Required.</h1>"; exit; } else { session_start(); session_register("sessionpass"); $_SESSION["sessionpass"]="1"; header( 'Location: http://www.somehostname.com/filename.php'); } ?> In this example, If the user and password are right, You can set $_SESSION["sessionpass"]="1" and then you can control this variable beginning of the PHP file like following. Begining of the filename.php <? session_start(); if (!session_is_registered ('sessionpass')) { echo "<h1>Authorization Required.</h1>"; exit; } ......... ......... ......... ......... ?> "Mike van Hoof" <mike@medusa.nl> wrote in message news:45ED2022.6040906@medusa.nl... > Hello, > > I've got a really strange problem, and hope this is the right list to > post to. > > I got a website with a login, which uses a .htaccess file for > autentication. That part works like a charm. But when i want to read the > loggin details with PHP, the variable $_SERVER['|PHP_AUTH_USER'] isn't > set (in the directory where i logged into) > > when i go a directory back, and view a phpinfo() there i see > |$_SERVER['|PHP_AUTH_USER']|| is set, so i do a phpinfo() in the > directory with the .htaccess and it is gone. > > Had anyone ever had experience with this, because i can't find a solution. > > - Mike| >

« previous php.db (#43257) next »