By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

LDAP authentication

P: 18
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\thesis\auth.php on line 21
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. echo $_POST['security_code'];
  4. $userid=$_POST['userid'];
  5. #echo $userid;
  6. $password=$_POST['password'];
  7. $server="10.2.0.12";        //change to ip address of ldap server
  8. $basedn="OU=EDU,DC=academic,DC=aua,DC=am";       //change to reflect the ou and domain that your users are in.
  9. #$script=$_SERVER['SCRIPT_NAME'];
  10.  
  11.  
  12.  
  13.  
  14.                 if ( ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) && (isset($userid)) && (isset($password))) 
  15.                 {
  16.  
  17.                      $filter="CN=$userid";
  18.                         #$filter="(&(|(!(displayname=Administrator*))(!(displayname=Admin*)))(cn=$username))"; 
  19.                                //define an appropriate ldap search filter to find your users, and filter out accounts such as administrator(administrator should be renamed anyway!).
  20.                         $dn = "CN=$userid";
  21.                                 if (!($connect = ldap_connect($server))) {
  22.                                         exit(0);
  23.                                 }
  24.                                  echo" after second connect";
  25.                                 if (!($bind = ldap_bind($connect,"$dn,"."$basedn",$password)))
  26.                                  {
  27.                                     #header("Location:newlog.php");
  28.  
  29.                                       exit(0);
  30.                                 }
  31.  
  32.                                   echo" after second bind";
  33.                 $sr = ldap_search($connect, $basedn,$filter);
  34.                 $info = ldap_get_entries($connect, $sr);
  35.                 if(!$sr)
  36.     {    
  37.  
  38.         #header("Location:newlog.php");
  39.         print "<br>anonymous search failed";
  40.         exit(0);
  41.     }
  42.     if($info["count"] == 0)
  43.     {   
  44.         #header("Location:newlog.php");
  45.         print "<br>User unknown";
  46.         exit(0);
  47.     }
  48.     if($info["count"] > 1)
  49.     {
  50.         #header("Location:newlog.php");
  51.         print "<br>More than one such user - report to CITS";
  52.         exit(0);
  53.     }
  54.                 #$fullname=$info[0]["displayname"][0];
  55.                 $fullname=$info[0]["givenname"][0]." ".$info[0]["sn"][0];
  56.                 echo $fullname;
  57.                # $fqdn=$info[0]["dn"];
  58.                 #echo $fqdn;
  59.  
  60.                 echo "<br>";
  61.                 $id =$info[0]["telephonenumber"][0];
  62.                 echo $id;
  63.                 echo "<br>";
  64.                 $mail= $info[0]["userprincipalname"][0];
  65.                 echo $mail;
  66.                 echo "<BR>";
  67.               print_r($_SERVER[SERVER_ADDR]);
  68.                   $d=date("Y-m-d H:i:s");
  69.                   echo "<BR>";
  70.                   #echo $d;
  71.                 setcookie("cookie[user]",$userid);
  72.                 setcookie("cookie[token]",$password);
  73.                 setcookie("cookie[fullname]",$mail);
  74.                 setcookie("cookie[fqdn]", $id);
  75.                # header("Location:traffic.php");
  76.         } else {
  77.        #header("Location:error.php");
  78.         die();
  79. }
  80. ?>
Jul 21 '07 #1
Share this Question
Share on Google+
3 Replies


mwasif
Expert 100+
P: 801
Call to undefined function ldap_connect()
you need to enable LDAP support.
Jul 21 '07 #2

pbmods
Expert 5K+
P: 5,821
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.
Jul 21 '07 #3

P: 20
to enable ldap in you'r php :

all you have to do is to uncomment the line :
extension=php_ldap.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!
Jul 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.