LDAPAuthPHP 介绍
LDAPAuthPHP 用来在 PHP 程序中执行 LDAP 身份验证。
示例代码:
PHP $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; }session_name(‘MYAPP’);
session_start();
if (!isset($_SESSION[“user”])) {
include(“LdapAuth.inc.PHP”);
$ldap=new LdapAuth();
$ldap->setSessionAttr(“user”,”uid”);
$ldap->setSessionName(“MYAPP”);
$ldap->setRedirectPage($pageURL); //page where we get redirected after login
(in this case self)
include(“LdapStandalonePageProtector.inc.PHP”);
}
else {
echo “Logged In As: “.$_SESSION[“user”].”“;
//paste here the old page code (or write the new page to protect)
}