Reputation: 1863
How to do above authentication in PHP.I already have my own authentication in php but how to do above type login screen.
Upvotes: 1
Views: 3348
Reputation: 1690
Instead of using Apache, you can do this in PHP: http://php.net/manual/en/features.http-auth.php
Basically, you have the username and password available in $_SERVER['PHP_AUTH_USER']
and $_SERVER['PHP_AUTH_PW']
, which you can use to lookup users in a database or whatever.
A basic example, from php.net:
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
Upvotes: 4
Reputation: 16953
That authentication is controlled by Apache, not PHP.
Take a look at this tutorial: http://www.seochat.com/c/a/Search-Engine-Optimization-Help/Apache-Basic-User-Authentication-htpasswd-Tutorial-for-SEO/
Upvotes: -1
Reputation: 3404
Try the following tutorial.
http://www.howtoforge.com/htaccess_authentication
http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html
Upvotes: 0