snippet library logo
The Best Html Forum Around
in category
PHP / Authentication / Login Authenticate
Snippet details
ID: 87
Viewed: 3387
Added: 2004-06-24
Version: php4.1+
Sorry no demo

User Rated at: 5 Stars
Rate This:
Snippets in this catagory         
Show Printable Version
This brings up a password window where the user has to enter a username and password. it then checks with Mysql to see if the username and password are real (compares it to the original). it then will load a page for the user to see or it will bring it up the password box again.<br><br>put the following in a seperate php file and include it on all your protected files: <br>

this will not work work if your server is setup in cgi mode.

General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: snippet

<!---Head--->
none

<!---Body--->


<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) { 

header('WWW-Authenticate: Basic realm="Login"'); 
header('HTTP/1.0 401 Unauthorized'); 
exit; 

} else if (isset(
$_SERVER['PHP_AUTH_USER'])) { 

$sql "SELECT * FROM users WHERE username='".htmlentities($_SERVER['PHP_AUTH_USER'])."' and password='".htmlentities($_SERVER['PHP_AUTH_PW'])."'"
$result mysql_query($sql); 
$num mysql_num_rows($result); 

if (
$num != 1) { 
header('WWW-Authenticate: Basic realm="Login"'); 
header('HTTP/1.0 401 Unauthorized'); 
exit; 
} else{ 
 
// show page you want them to see here




?>




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.