Re: HTTP Auth

From: Date: Wed, 09 May 2001 23:51:14 +0000
Subject: Re: HTTP Auth
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-52199@lists.php.net to get a copy of this message
Thanks Ive fixed my problem.............. "Thomas Edison Jr." wrote: > Try using this : > > <?php > $auth = false; // Assume user is not authenticated > if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { > > mysql_connect('localhost','root') or die ( > 'Unable to connect to server.' ); > mysql_select_db( 'myDB' ) or die ( 'Unable to > select database.' ); > > // Formulate the query > > $sql = "SELECT * FROM myTable WHERE > username = '$PHP_AUTH_USER' AND > password = '$PHP_AUTH_PW'"; > > // Execute the query and put results in $result > > $result = mysql_query( $sql ) or die ( 'Unable to > execute query.' ); > > // Get number of rows in $result. > $num = mysql_numrows( $result ); > if ( $num != 0 ) { > > // A matching row was found - the user is > authenticated. > > $auth = true; > } > } > > if ( ! $auth ) { > > header( 'WWW-Authenticate: Basic realm="Private"' > ); > header( 'HTTP/1.0 401 Unauthorized' ); > echo 'Authorization Required.'; > exit; > > } else { > > ***your stuff goes here when authenticated**** > > } > ?> > > works excellent on any browser, apache server with PHP > module. > > T. Edison jr. > > --- gary <gary@busted.net.au> wrote: > > Im having a problem with Authentication uisng > > $PHP_AUTH_USER and > > $PHP_AUTH_PASSWORD works fine connecting via > > netscape but automatically > > set to false when using IE 5. Apache server , PHP > > installed as a module > > on a freebie server. Code below: > > <?php > > > > // Assume user is not authenticated > > > > if (isset($PHP_AUTH_USER) && isset($PHP_AUTH_PW)) { > > > > // Connect to database > > $conn = pg_pconnect ("dbname=".$db.$login); > > // Select database on MySQL server > > > > > > // Formulate the query > > > > $sql = "SELECT * FROM ".$table2." WHERE > > username = '$PHP_AUTH_USER' AND > > password = '$PHP_AUTH_PW' and valid ='y'"; > > > > // Execute the query and put results in $result > > > > $result = pg_Exec ( $sql ); > > > > // Get number of rows in $result. > > > > $num = pg_numrows( $result ); > > if ( $num != 0 ) { > > // A matching row was found - the user is > > authenticated. > > $auth = true; > > } > > } > > if ( ! $auth ) { > > header("WWW-Authentucate: Basic > > realm=\"Private\"\\n"); > > Header ("Status: 401 Unauthorized\n"); > > header("HTTP/1.0 401 Unauthorized\n"); > > echo 'Authorization Required.<br>'; > > echo 'Please go to <a > > href=./index,php?pg=REGISTER>Registration</a> > > page to Get a logon, It is Free.'; > > echo > > > > "<br><b>???????".$PHP_AUTH_USER."<br>???????".$PHP_AUTH_PW."</b>"; > > exit; > > } else { > > } > > pg_close($conn); > > ?> > > > > > > -- > > 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 > > > > ===== > Rahul S. Johari (Director) > ****************************************** > Abraxas Technologies Inc. > Homepage : http://www.abraxastech.com > Email : abraxastech@yahoo.com > Tel : 91-4546512/4522124 > ******************************************* > > __________________________________________________ > Do You Yahoo!? > Yahoo! Auctions - buy the things you want at great prices > http://auctions.yahoo.com/ > > -- > 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 (#52199) next »