Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Authentication Code Examples

Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate

Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate <? if(!isset($PHP_AUTH_USER)) { Header("WWW-authenticate: basic realm=\"XXX\""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; ?> <blockquote> In order to enter this section of the web site, you must be an XXX subscriber. If you are a subscriber and you are having trouble logging in, please contact <a href="mailto:[email protected]">[email protected]</a>. </blockquote> <? exit; } else { mysql_pconnect("localhost","nobody","") or die("Unable to connect to SQL server"); mysql_select_db("xxx") or die("Unable to select database"); $user_id=strtolower($PHP_AUTH_USER); $password=$PHP_AUTH_PW; $query = mysql_query("select * from users where user_id='$user_id' and password='$password'"); if(!mysql_num_rows($query)) { Header("WWW-authenticate: basic realm=\"XXX\""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; ?> <blockquote> In order to enter this section of the web site, you must be an XXX subscriber. If you are a subscriber and you are having trouble logging in, please contact <a href="mailto:[email protected]">[email protected]</a>. </blockquote> <? exit; } /* Here I pick out some other useful info from my database that then available to any script that includes this file */ $name=mysql_result($query,0,"name"); $email=mysql_result($query,0,"email"); mysql_free_result($query); } ?>