Return to Snippet

Revision: 9997
at December 3, 2008 02:00 by jadedbat


Updated Code
<?php

// input user/pass below
$username = "INSERT YOUR DESIRED USERNAME HERE";
$password = "INSERT YOUR DESIRED PASSWORD HERE";

// password protect via http
if(!(isset($_SERVER['PHP_AUTH_USER']) && 
	isset($_SERVER['PHP_AUTH_PW']) && 
	$_SERVER['PHP_AUTH_USER'] == $username &&
	$_SERVER['PHP_AUTH_PW'] == $password)){
		header('WWW-Authenticate: Basic realm="Secured Area"');
		header('Status: 401 Unauthorized');
		}else{
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Page Name</title>
</head>

<body>
<!-- // html -->
</body>
</html>
<?php } ?>

Revision: 9996
at December 3, 2008 01:57 by jadedbat


Initial Code
<?php

// input user/pass below
$username = "INSERT YOUR DESIRED USERNAME HERE";
$password = "INSERT YOUR DESIRED PASSWORD HERE";

// password protect via http
if(!(isset($_SERVER['PHP_AUTH_USER']) && 
	isset($_SERVER['PHP_AUTH_PW']) && 
	$_SERVER['PHP_AUTH_USER'] == $username &&
	$_SERVER['PHP_AUTH_PW'] == $password)){
		header('WWW-Authenticate: Basic realm="Secured Area"');
		header('Status: 401 Unauthorized');
		}else{
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>File Upload</title>
<style type="text/css">
body {font-family:Lucida Grande, "Lucida Sans", arial; font-size:1.3em; color:#555;}
</style>
</head>

<body>
<!-- // html -->
</body>
</html>
<?php } ?>

Initial URL
http://www.thatgrafix.com

Initial Description
I thought I would share this simple username password PHP auth script.  It leans on HTTP to secure a page.. not bulletproof but quick and painless.

Initial Title
Simple PHP Authentication HTTP

Initial Tags
php

Initial Language
PHP