Authenticating user using LDAP from PHP

前端 未结 4 1373
礼貌的吻别
礼貌的吻别 2020-12-12 17:13

My project is to make a module enrollment system for our university. So I contacted the IT people in my university for details to authenticate the students into the system.

4条回答
  •  天命终不由人
    2020-12-12 17:52

    @Stephen provided good points. Here is my plain PHP code to authenticate using AD:

    1. first you need to know this parameters: server host, user domain (you need also base dn if you want query AD).
    2. use the following code:

      $ldap = ldap_connect($host); // e.g. 165.5.54.6 or an URL
      ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); // Recommended for AD
      ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
      $bind = ldap_bind($ldap, $username.'@'.$userDomain, $passwrod);
      
      if($bind){
      // successful authentication. 
      }
      

提交回复
热议问题