note 118089 added to features.http-auth
| From: | dan223 at gmail dot com | Date: | Thu, 01 Oct 2015 22:45:03 +0000 |
| Subject: | note 118089 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203890@lists.php.net to get a copy of this message | ||
A simple script for SSL Client Certificate authentication with a basic authentication fall-back. I
use this on my site using LDAP server to check username/passwords and client certificate to user
mapping.
<?
// Check if and how we are authenticated
if ($_SERVER['SSL_CLIENT_VERIFY'] != "SUCCESS") { // Not using a client
certificate
if ((!$_SERVER['PHP_AUTH_USER']) && (!$_SERVER['PHP_AUTH_PW'])) { //
Not logged in using basic authentication
authenticate(); // Send basic authentication headers
}
}
if ($_SERVER['SSL_CLIENT_S_DN_CN'] != "chris") { // Check CN name of cert
if (!(($_SERVER['PHP_AUTH_USER'] == "test") &&
($_SERVER['PHP_AUTH_PW'] == "123"))) { // Check username and password
authenticate(); // Send basic authentication headers because username and/or password didnot
match
}
}
phpinfo();
// Call authentication display
function authenticate() {
Header("WWW-Authenticate: Basic realm=Website");
Header("HTTP/1.0 401 Unauthorized");
error401();
exit;
}
?>
See my website (http://velocitypress.ca/index.php?page=/manuals/) for more details on client
certificate with Apache and PHP.
----
Server IP: 72.52.91.14
Probable Submitter: 68.146.148.38
----
Manual Page -- http://php.net/manual/en/features.http-auth.php
Edit -- https://master.php.net/note/edit/118089
Del: integrated -- https://master.php.net/note/delete/118089/integrated
Del: useless -- https://master.php.net/note/delete/118089/useless
Del: bad code -- https://master.php.net/note/delete/118089/bad+code
Del: spam -- https://master.php.net/note/delete/118089/spam
Del: non-english -- https://master.php.net/note/delete/118089/non-english
Del: in docs -- https://master.php.net/note/delete/118089/in+docs
Del: other reasons-- https://master.php.net/note/delete/118089
Reject -- https://master.php.net/note/reject/118089
Search -- https://master.php.net/manage/user-notes.php