mantis ldap active directory

Posted on 2009-04-27
Last Modified: 2013-12-24
i am geting errror  in ldap_bind functin

ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in

$server="";    //change to ip address of ldap server 

$basedn="cn=tarun sadan tiwari(243917),dc=example,dc=com";    //change to reflect the ou 


if (isset($HTTP_COOKIE_VARS['cookie'])) {       //If cookie exists, retrieve it and 



if (isset($cookie)) {  










    $dn = "cn=$username, "; 



        if (!($connect = ldap_connect($server))) { 

            die ("Could not connect to LDAP server"); 


        if (!($bind = ldap_bind($connect, "$dn" . "$basedn", $password))) { 

                   die ("Could not bind to $dn$basedn"); 


    } else { 

        if ((isset($_POST['username'])) && (isset($_POST['password']))) { 




(displayname=Tiwari)))(cn=$username))";*/   //define an appropriate ldap search filter 

            $dn = "cn=$username, "; 

                if (!($connect = ldap_connect($server))) { 

                    die ("Could not connect to LDAP server"); 


echo $connect.$dn.$basedn;

                if (!($bind = ldap_bind($connect, "$dn" . "$basedn", 

$password))) { 

                    die ("Could not bind to $dn"); 


                echo $connect;

       $sr = ldap_search($connect, $basedn,"$filter"); 

       // $sr = ldap_search($connect,"OU=orginizational unit,DC=domain,DC=com", "");

        $info = ldap_get_entries($connect, $sr); 






        setcookie("cookie[fqdn]", $fqdn); 

    } else { 




<title>Portal Login</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

<meta http-equiv="expires" content="0"> 

<meta http-equiv="pragma" content="no-cache"> 





        function click() 


            if (event.button==2) {alert('Right-clicking has been 

disabled by 

the administrator.');} 





<div align="center"> 

  <form method="post" action="<? echo $script; ?>"> 

         <div align="center"> 


             <table width="210" border="0" cellspacing="0" cellpadding="0"> 


              <td align="center"> 


                 <Legend><font face="Verdana,Tahoma,Arial,sans-serif" size="1" 

color="gray">Enter Credentials</font></Legend> 

                    <table border="0" cellspacing="3" cellpadding="0"> 


                        <td align="right" valign="middle"><b><font 


serif" size="1" color="gray">Username:</font></td> 

                        <td align="center" valign="middle"> 

                          <input class="clear" type="text" size="15" name="username"> 




                        <td align="right" valign="middle"><b><font 


serif" size="1" color="gray">Password:</font></td> 

                        <td align="center" valign="middle"> 

                          <input class="pass" type="password" size="15" 





                    <input type=image src="images/login.gif" alt="Login" 









             <table width="640"><tr><td align="center"> 

             <font face="Verdana,Tahoma,Arial,sans-serif" size="1" 

color="silver">This System is 

for the use of authorized users only.  Individuals using this computer system 


authority, or in excess of their authority, are subject to having their activities 

on this system 

monitored and recorded by system personnel.  In the course of monitoring individuals 

improperly using this system, or in the course of system maintenance, the activities 


authorized users may also be monitored. Anyone using this system expressly consents 


such monitoring and is advised that if such monitoring reveals possible criminal 


system personnel may provide the evidence of such monitoring to law enforcement 


This warning has been provided by the United States Department of Justice and is 

intended to 

ensure that monitoring of user activity is not in violation of the Communications 

Privacy Act of 










die (); 




Open in new window

Question by:taruntiwari
    LVL 3

    Assisted Solution

    Does this program run on a windows machine? If yes,I dont see a reason why you hardcode an ldap server ip address, you should use serverless bind instead. Btw did you try with the FQDN of the server?
    LVL 70

    Accepted Solution


    Verify that the server running this code can connect to Port 389 on the server specified. Telnet can be used to test that:

    telnet 389

    Success is indicated by a blank screen, failure by it saying the connection failed.


    Author Closing Comment

    still not able to make mantis user to authenticate.
    LVL 70

    Expert Comment

    by:Chris Dent

    Why did you close the question then? :)

    Has it successfully connected now?

    I'm not convinced this value can be correct:

    $basedn="cn=tarun sadan tiwari(243917),dc=example,dc=com"

    If it's an OU then the prefix is OU= not CN=. e.g.

    $basedn = "ou=tarun sadan tiwari(243917),dc=example,dc=com"

    What value are you giving to this?

    $dn = "cn=$username

    If find the way it builds the authentication string to be pretty crap, I would change that. At the moment the user used to create the connection has to live in the same OU as the search base.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now