Skip to content

Instantly share code, notes, and snippets.

@pmbaldha
Created March 15, 2016 04:32
Show Gist options
  • Save pmbaldha/f81bad50095652b04661 to your computer and use it in GitHub Desktop.
Save pmbaldha/f81bad50095652b04661 to your computer and use it in GitHub Desktop.
HTTP Basic authentication in php
//For http basic authentication in php
//Just add this code on top before any echo or print in common file
$user = 'user';
$password = 'pass';
if (!($_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $password)) {
header('WWW-Authenticate: Basic realm="Please enter username and password to access tgis website"');
header('HTTP/1.0 401 Unauthorized');
echo '<h1>Unauthorized Access</h1>';
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment