Re: sending header

From: Date: Thu, 07 Dec 2000 14:29:11 +0000
Subject: Re: sending header
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29135@lists.php.net to get a copy of this message
This is for PHP, and is essentially courtesy of Rasmus Lerdorf ... <? require( "dbname.inc" ); function authenticate() { Header("WWW-authenticate: basic realm=\"Auction Maintenance\""); Header("HTTP/1.0 401 Unauthorized"); $title="Invalid Login"; include( 'header.inc' ); ?> In order to proceed you will need a valid username/password. <?include ("footer.inc"); exit; } if(!isset($PHP_AUTH_USER)) { authenticate(); } else { mysql_pconnect("localhost","root") or die("Unable to connect to SQL server"); mysql_select_db( "$auction" ) or die("Unable to select database"); $login_id=strtolower($PHP_AUTH_USER); $query = mysql_query("select * from admin where cAdminId='$login_id'". " and cPassword='$PHP_AUTH_PW'"); if(!mysql_num_rows($query)) { authenticate(); } else { include( 'header.inc' ); } } ?> The dbname.inc contains the database name as they are different on production and development systems. Watch that you have no empty lines which could get sent to the browser ahead of the header. For example, this doesn't work, although it looks as if it should: <? require( "dbname.inc" ); function authenticate() { Hea ... etc. Miles Thompson Robert Ludvik wrote: > hi > i set up auth. on my page with $PHP_AUTH_USER and _PW. problem is that > if user type in ie. wrong passwd, program says that "he is not allowed > to see this page...blah blah". how do i implement another login > window. i tried to set it like function : > > function auth() { > header( 'WWW-Authenticate: Basic realm="Private"' ); > header( 'HTTP/1.0 401 Unauthorized' ); > echo ("...blah blah..\n"); > exit; > } > > and later > > if ((!isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))) > auth(); > else { > > ...look in Postgres db to find a name and passwd, > if found ok, > else auth(); > > but this doesn't work. > it reports an error "Warning: Cannot add header information - headers > already sent by " > i get the problem - sending header twice - how can i solve this??? > > thnx robert > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#29135) next »