Created
March 15, 2016 04:32
-
-
Save pmbaldha/f81bad50095652b04661 to your computer and use it in GitHub Desktop.
HTTP Basic authentication in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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