LDAP authentication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akkad
    New Member
    • Jun 2007
    • 18

    #1

    LDAP authentication

    hi every body.

    my question is : how to authenticate with LDAP server from the localhost (WAMP) ?

    coz when i am trying to authenticate using the same code that i have on the linux server (working perfectly) it is giving me the following error message:

    Fatal error: Call to undefined function ldap_connect() in C:\wamp\www\the sis\auth.php on line 21
    [code=php]
    <?php
    session_start() ;
    echo $_POST['security_code'];
    $userid=$_POST['userid'];
    #echo $userid;
    $password=$_POS T['password'];
    $server="10.2.0 .12"; //change to ip address of ldap server
    $basedn="OU=EDU ,DC=academic,DC =aua,DC=am"; //change to reflect the ou and domain that your users are in.
    #$script=$_SERV ER['SCRIPT_NAME'];




    if ( ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSI ON['security_code'])) && (isset($userid) ) && (isset($passwor d)))
    {

    $filter="CN=$us erid";
    #$filter="(&(|( !(displayname=A dministrator*)) (!(displayname= Admin*)))(cn=$u sername))";
    //define an appropriate ldap search filter to find your users, and filter out accounts such as administrator(a dministrator should be renamed anyway!).
    $dn = "CN=$userid ";
    if (!($connect = ldap_connect($s erver))) {
    exit(0);
    }
    echo" after second connect";
    if (!($bind = ldap_bind($conn ect,"$dn,"."$ba sedn",$password )))
    {
    #header("Locati on:newlog.php") ;

    exit(0);
    }

    echo" after second bind";
    $sr = ldap_search($co nnect, $basedn,$filter );
    $info = ldap_get_entrie s($connect, $sr);
    if(!$sr)
    {

    #header("Locati on:newlog.php") ;
    print "<br>anonym ous search failed";
    exit(0);
    }
    if($info["count"] == 0)
    {
    #header("Locati on:newlog.php") ;
    print "<br>User unknown";
    exit(0);
    }
    if($info["count"] > 1)
    {
    #header("Locati on:newlog.php") ;
    print "<br>More than one such user - report to CITS";
    exit(0);
    }
    #$fullname=$inf o[0]["displaynam e"][0];
    $fullname=$info[0]["givenname"][0]." ".$info[0]["sn"][0];
    echo $fullname;
    # $fqdn=$info[0]["dn"];
    #echo $fqdn;

    echo "<br>";
    $id =$info[0]["telephonenumbe r"][0];
    echo $id;
    echo "<br>";
    $mail= $info[0]["userprincipaln ame"][0];
    echo $mail;
    echo "<BR>";
    print_r($_SERVE R[SERVER_ADDR]);
    $d=date("Y-m-d H:i:s");
    echo "<BR>";
    #echo $d;
    setcookie("cook ie[user]",$userid);
    setcookie("cook ie[token]",$password );
    setcookie("cook ie[fullname]",$mail);
    setcookie("cook ie[fqdn]", $id);
    # header("Locatio n:traffic.php") ;
    } else {
    #header("Locati on:error.php");
    die();
    }
    ?>[/code]
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Call to undefined function ldap_connect()
    you need to enable LDAP support.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Akkad, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page the next time you post.

      Comment

      • hamarsheh
        New Member
        • Jun 2007
        • 20

        #4
        to enable ldap in you'r php :

        all you have to do is to uncomment the line :
        extension=php_l dap.dll
        in the php.ini file .


        to know more about using ldap in php , type read user permissions in the search field in forum page , and you will find solutions we got , see the one posted by me (hamarsheh).

        good luck!

        Comment

        Working...