我正在为我的公司开发一个需要用户登录的应用程序。 为了自动化登录过程,我尝试将ldap id和密码身份验证与此应用程序集成。下面是我为此集成编写的代码。我在网上查了一下,找不到任何一个面临这个问题的人。
我有这段代码 - >
function isAuthenticated($u,$p) {
$ldap_host = 'my_host';
$ldap = ldap_connect($ldap_host);
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
if($ldap) {
if($bind = ldap_bind($ldap,$u,$p)) {
ldap_unbind($ldap);
return 'Authenticated';
} else {
return 'Invalid Credentials';
}
} else {
return 'Not able to connect';
}
}
$username = 'preventAnonymousLogin';
$password = 'preventAnonymousLogin';
if(isset($_REQUEST['uname'])) {
$username = $_REQUEST['uname'];
}
if(isset($_REQUEST['password'])) {
$password = $_REQUEST['password'];
}
$auth = isAuthenticated($username,$password);
这大部分时间都有效,但有时却没有,并给出了这个错误 - >
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\avrs\htdocs\ldap.php on line 12
我不知道为什么这会有效,有时却不行。请建议。提前谢谢。
这段代码间歇性地工作。我试图清除饼干,所有这些似乎都有效,但今天不是。所以,除非我确定问题是什么,否则我认为我无法解决这个问题。
答案 0 :(得分:1)
确保您提供ldap_host的完整DNS名称,例如myhost.mydomain.com。
答案 1 :(得分:0)
根据错误,您可以尝试将C:\ xampp \ htdocs \ avrs \ htdocs \ ldap.php中的最大脚本执行时间设置为60秒或大于30秒的内容。从上面的代码看起来就像
function isAuthenticated($u,$p) {
set_time_limit(60);
// Rest of your code from above
}
答案 2 :(得分:0)
看看这些例子。第一个是非常简单的LDAP /活动目录登录脚本。第二个实际上是为Yii框架构建的,但它更强大,因为它处理使用多个服务器,以防其中一个服务器停机。