Simple Password Protect Category Pages

Using htaccess, godaddy, php, cgi fix, $_SERVER[‘PHP_AUTH_USER’], $_SERVER[‘PHP_AUTH_PW’]

Fixes:
godaddy login keeps on popping up (popup) due to cgi mode.

Works on Specific Categories


See code fix:

1. PHP FILE


$pageurl=$_SERVER[REQUEST_URI];

if(($pageurl=='/categories/x')||($pageurl=='/categories/y')){

if(isset($_SERVER['HTTP_AUTHORIZATION'])) {
$auth_params = explode(":" , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
$_SERVER['PHP_AUTH_USER'] = $auth_params[0];
unset($auth_params[0]);
$_SERVER['PHP_AUTH_PW'] = implode('',$auth_params);
}

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm="Private Area"");
header("HTTP/1.0 401 Unauthorized");
print "Sorry - you need valid credentials to be granted access! Try again by refreshing this page. Refresh Pagen";
exit;
} else {
if (($_SERVER['PHP_AUTH_USER'] == 'username') && ($_SERVER['PHP_AUTH_PW'] == 'password')) {

} else {
header("WWW-Authenticate: Basic realm="Private Area2"");
header("HTTP/1.0 401 Unauthorized");
print "Sorry - you need valid credentials to be granted access! Try again by refreshing this page. Refresh Pagen";
exit;
}
}
}

2. HTACCESS (linux)


RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

Great ideas for gaining authority links

  • chamber of commerce
  • trade organizations
  • local news sites (i.e. latimes.com, ocregister.com)
  • local university pages (discounts, resource pages)
  • donations (local or nationwide businesses, non-profits, etc)
  • radio and news stations (also try npr for a story)
  • interview authority in niche (or write an article that mentions authority plus mention this to them)
  • certification listings
  • conferences
  • city websites (losangeles.com)
  • EDU