Skip to content

Instantly share code, notes, and snippets.

View pmbaldha's full-sized avatar
🏠
Working from Home

Prashant Baldha pmbaldha

🏠
Working from Home
View GitHub Profile
@pmbaldha
pmbaldha / http_basic_authentication.php
Created March 15, 2016 04:32
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;
}