How can I use my .htpasswd login "session" all across my site? I want to be able to login to via /admin.php using my .htpasswd account, then display certain admin features on other pages, ex. /browse.php, if the admin is logged in.
Here's what I tried, which didn't work.
if (isset($_SERVER["PHP_AUTH_USER"]) && $_SERVER["PHP_AUTH_USER"] == "admin") {
$reportLink = "<a href=\"browse.php?url=" . $url . "&report=" . $site_id . "\" style=\"color: #FFFFFF;\">Report Dead Link?</a>";
if($_GET["report"] == $site_id && preg_match("/^\d+$/", $site_id) && $_SERVER["PHP_AUTH_USER"] == "admin") {
mysql_query("UPDATE `websites` SET `status` = '4' WHERE `id` = '$site_id'") or die(mysql_error());
header("Location: browse.php");
} else {
header("Location: anotherpage.php");
}
}
Ensure that your other pages are password protected under the same scheme, then the browser will re-submit the auth details for each one.
You know, PHP sessions are far more flexible for this kind of thing...