leungeric.com

Digg del.icio.us Technorati StumbleUpon Twitter

Password Protection using WWW-Authenticate

Code Snippets | PHP

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

This creates simple login function using the WWW-Authenticate header.

<?php
 
// Define your username & password
$username = 'admin';
$password = 'admin';
 
$login_successful = false;
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
	$usr = $_SERVER['PHP_AUTH_USER'];
	$pwd = $_SERVER['PHP_AUTH_PW'];
	if ($usr == $username && $pwd == $password){
		$login_successful = true;
	}
}
 
if (!$login_successful){
	header('WWW-Authenticate: Basic realm="Protected Area"');
	header('HTTP/1.0 401 Unauthorized');
	print "Login failed!\n";
	exit();
}
?>
  • Digg
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Reddit
  • TwitThis
  • Sphinn
  • BlinkList
  • Furl
  • Mixx
  • NewsVine
  • Slashdot
  • Ma.gnolia
  • Facebook
  • Google
  • E-mail this story to a friend!

No Comments, Comment or Ping

Reply to “Password Protection using WWW-Authenticate”

Sponsors