[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


mantis ldap active directory

Posted on 2009-04-27
Medium Priority
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
  • 2

Assisted Solution

a_ro_no earned 300 total points
ID: 24248696
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 71

Accepted Solution

Chris Dent earned 450 total points
ID: 24248700

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

ID: 31575318
still not able to make mantis user to authenticate.
LVL 71

Expert Comment

by:Chris Dent
ID: 24248978

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.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

872 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