简体   繁体   English

PHP LDAP用户身份验证不起作用

[英]PHP LDAP user authentification not working

I am trying to implement a LDAP connection through PHP for an internal web page. 我正在尝试通过PHP为内部网页实现LDAP连接。 I use Uniform Server for my PHP. 我为PHP使用统一服务器。 http://www.uniformserver.com/ . http://www.uniformserver.com/ As a test I am trying to connect to the test server here. 作为测试,我试图在这里连接到测试服务器。 http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

But I don't understand it seem like it doesn't even go in the if/else statements. 但是我不明白,它似乎甚至不在if / else语句中。

Here's my code : 这是我的代码:

<?php

$ldapServer = 'ldap.forumsys.com';
$ldapPort = 389;

if(isset($_POST['username']) && isset($_POST['password'])){
    echo "Hello both parameters are set";
    $username = $_POST['username'];
    $password = $_POST['password'];
    echo "<br>" . $username;
    echo "<br>" . $password;
    $ds = ldap_connect($ldapServer, $ldapPort);

    if (ldap_bind($ds, $_POST['username'], $_POST['password'])) {
        // Successful auth
        $_SESSION['username'] = $_POST['username'];
        $_SESSION['password'] = $_POST['password'];
        // log them in!
        echo 'you are logged in ' . $_SESSION['username'] ;    
        //redirect after logged in2
    } else {
        // error message

        echo 'auth failed';
    }
}
else
{
?>
    <form action="login.php" method="POST">
        <label for="username">Username: </label><input id="username" type="text" name="username" required="true" /> 
        <label for="password">Password: </label><input id="password" type="password" name="password" required="true" />        <input type="submit" name="submit" value="Submit" />
    </form>
<?php
 } ?> 

My first echos are shown (password and username) but nothing after that is shown. 显示了我的第一个回声(密码和用户名),但此后未显示任何内容。 Anyone sees why? 有人知道为什么吗? I don' have any errors but here's my response. 我没有任何错误,但这是我的回复。

Hello both parameters are set
username
password

Thanks 谢谢

First things first, check if you're getting a connection. 首先,请检查是否已建立连接。 The below snippet is one way of checking this: 以下代码段是一种检查方式:

if ($ds) {
// Successful connection
} else {
echo "Error connecting";
}

My guess is you're seeing the echo portion because they're outside the ldap_bind , while you're not getting a bind because your connection is failing. 我的猜测是,您看到回显部分是因为它们在ldap_bind之外,而您没有得到绑定是因为您的连接失败了。 Double check the server address and/or try using an IP address. 仔细检查服务器地址和/或尝试使用IP地址。 Note you can safely drop the port at this stage as 389 is default, so simply using 请注意,您可以在此阶段安全删除端口,因为默认为389,因此只需使用

$ds=ldap_connect("ip/address");

Would work fine. 会很好的。

Now, since you're hitting what appears to be an external domain address it may be LDAPS, so double check that (Or maybe it's not). 现在,由于您要查找的是外部域地址,因此它可能是LDAPS,因此请仔细检查(或可能不是)。 If this is the case, you will need 在这种情况下,您将需要

$ds = ldap_connect('ldaps://ip', 636);

Let me know if any of this has helped 让我知道这是否有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM