LDAP身份验证无效

时间:2016-06-22 09:06:00

标签: php authentication ldap

我尝试使用PHP在我的网站上进行LDAP身份验证,但它不起作用。我试图解决问题,我无法找到我的代码有什么问题。

function loging_check(){

if(isset($_POST['login'])){

    $myusername=$_POST['username'];
    $mypassword=$_POST['password'];
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);

    $sqlcheckuser="SELECT COUNT(*) FROM employee WHERE usrename='".$myusername."'";
    $resultcheckuser=mysql_query($sqlcheckuser);
    $rowcheckuser = mysql_fetch_array($resultcheckuser);
    $numrecords=$rowcheckuser[0];

    $res=mysql_query("Select * from employee where username ='$myusername'")or die("query error".mysql_error());
    $row=mysql_fetch_array($res);

    if($numrecords ==1){

        $usrname=$row['username'];

        $ldapconfig['host'] = '**.***.*.**';
        $ldapconfig['port'] = ***;
        $ldapconfig['basedn'] ='dc=***,dc=**';
        $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);

        $dn="emp_id=".$usrname.",".$ldapconfig['basedn'];
        $password=$mypassword;

    if (@ldap_bind($ds, $dn, $password))
    {
        $sql="SELECT employee.* FROM employee WHERE employee.usrename='$myusername'";
        $result=mysql_query($sql);
        $row = mysql_fetch_array($result);

        session_start();
        $_SESSION['username'] = $myusername;
        header('Location: index.php');
    }

else{
    echo '<div class="alert alert-danger" role="alert" id="note">'."Username or password is incorrect".'</div>';
}
}}}

请帮助我!

0 个答案:

没有答案