Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<?php
function auth_user() {
$realm = mt_rand( 1, 1000000000 );
header('[URL unfurl="true"]WWW-Authenticate:[/URL] Basic realm="Realm ID='.$realm.']"');
header('HTTP/1.0 401 Unauthorized');
die("Unauthorized access forbidden!");
}
if (!isset($_SERVER['PHP_AUTH_USER'])) {
auth_user();
} else if (!isset($_SERVER['PHP_AUTH_PW'])) {
auth_user();
} else if ($_SERVER['PHP_AUTH_USER'] != $auser || $_SERVER['PHP_AUTH_PW'] != $apass) {
auth_user();
} else if (isset($_GET['action']) && $_GET['action'] == "logout") {
auth_user();
}
// Normal Page Code Here
?>
When you try to access a site which has been protected by .htaccess your browser will pop up a standard username/password dialog box. If you don't like this, there are certain scripts available which allow you to embed a username/password box in a website to do the authentication. You can also send the username and password (unencrypted) in the URL as follows: