PHP and Active Directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andyt_2000_uk@yahoo.co.uk

    PHP and Active Directory

    Hi

    I'm trying to get it so visitors to our intranet site are able to log
    into the site with there normal login details. On a network using
    win2k3, active directory etc.

    Now my code at the moment seems to connect to AD but it fails when it
    trys to bind.

    <?php
    //Connect to Active Directory
    $ad = ldap_connect("h ole.chase.local , 389") or
    die("Couldn't connect to AD!"."<br />");
    echo "connect result is " . $ad . "<br />";

    //set protocol version
    if (ldap_set_optio n($ds, LDAP_OPT_PROTOC OL_VERSION, 3)) {
    echo "Using LDAPv3". "<br />";
    } else {
    echo "Failed to set protocol version to 3";
    }

    $ldaprdn = 'andy';
    $ldappass = 'password';

    //Bind to Active Directory
    if ($ad){
    $bd = ldap_bind($ad, $ldaprdn, $ldappass) or
    die("Couldn't bind to AD!");
    }
    if ($bd){
    echo "success"." <br />";
    } else {
    echo "fail"."<br />";
    }
    ?>

    Everytime it runs it dies, saying Couldn't bind to AD!

    Checking the logs for apache i notice it reports

    [client 127.0.0.1] PHP Warning: ldap_bind(): Unable to bind to
    server: Can't contact LDAP server in F:\\Website\\ht docs\\example3. php
    on line 23

    Any ideas on how to solve this would be great.

    Cheers

    Andy

  • NC

    #2
    Re: PHP and Active Directory

    andyt_2000_uk@y ahoo.co.uk wrote:[color=blue]
    >
    > I'm trying to get it so visitors to our intranet site are able to log
    > into the site with there normal login details. On a network using
    > win2k3, active directory etc.
    >
    > Now my code at the moment seems to connect to AD but it fails
    > when it trys to bind.[/color]

    Of course it does... Consider a few changes to your code:

    //Connect to Active Directory
    $ad = ldap_connect('h ole.chase.local ', 389)
    // First change ^^^^^^^^^^^^^^^ ^^^^^^^^
    or die("Couldn't connect to AD!"."<br />");
    echo "connect result is " . $ad . "<br />";
    //set protocol version
    if (ldap_set_optio n($ad, LDAP_OPT_PROTOC OL_VERSION, 3)) {
    // Second change ^^
    echo "Using LDAPv3". "<br />";
    } else {
    echo "Failed to set protocol version to 3";
    }
    $ldaprdn = 'andy';
    $ldappass = 'password';
    //Bind to Active Directory
    if ($ad) {
    $bd = ldap_bind($ad, $ldaprdn, $ldappass)
    or die("Couldn't bind to AD!");
    }
    if ($bd) {
    echo "success"." <br />";
    } else {
    echo "fail"."<br />";
    }

    Cheers,
    NC

    Comment

    • andyt_2000_uk@yahoo.co.uk

      #3
      Re: PHP and Active Directory

      Cheers, didn't spot those 2 mistakes.

      Unfortunately i still get the same errors of not being able to bind to
      AD.

      Comment

      • David  Wahler

        #4
        Re: PHP and Active Directory

        andyt_2000_uk@y ahoo.co.uk wrote:[color=blue]
        > Unfortunately i still get the same errors of not being able to bind to
        > AD.[/color]

        Try changing:
        die("Couldn't bind to AD!");
        to:
        die("Couldn't bind to AD: " . ldap_error($ad) );

        As it is, you're suppressing all the useful information that might help
        you solve the problem.

        -- David

        Comment

        • Uchi

          #5
          Re: PHP and Active Directory

          May be your server name is not correct
          try using

          $ds = ldap_server("lo calhost");

          or

          $ds = ldap_server("ld ap://localhost");

          if you are doing it on the server it self otherwise look for the
          correct name that could be the problem as well....

          Uchi

          Comment

          • andyt_2000_uk@yahoo.co.uk

            #6
            Re: PHP and Active Directory

            Cheers all for the help, it appears there was a DNS issue on the 2k3
            box and so the ldap server name wasn't getting resolved.

            Cheers

            Comment

            Working...