简体   繁体   中英

There is no return value from ldap_connect() php

Currently, I'm working on PHP web application on wamp environment.

I'm quite new with ldap and right now, I have a pretty simple problem about it.

After I enabled LDAP support in PHP. I have tried to call ldap function with the following code:

<?php

// LDAP variables
$ldaphost = "ldap.example.com";  // your ldap servers
$ldapport = 389;                 // your ldap server's port number

// Connecting to LDAP
$ldapconn = ldap_connect($ldaphost, $ldapport)
          or die("Could not connect to $ldaphost");

echo $ldapconn;

?>

The problem is when I run this file, I've got no result. I can't see whether it's failed or not and after function "ldap_connect", whatever I tried to put it there. It doesn't work, even simple command eg echo "hello world";

What should I do?

Please Suggest.

I hope my necropost will help someone with same problem.

On CentOS 6.6 with php 5.3.3 ldap_bind also returned NULL .

Firstly, I have found that ldap_connect does not actually connect to LDAP server. It only parses connect data.

Then I discovered that my virtual machine had one hell of a mess with network interfaces and was just unable to contact LDAP server.I fixed network interfaces and everything started to work fine. So it seems that NULL is returned when LDAP server is unavailable due to network errors - may be network interfaces, firewall, etc.

ldap_connect returns resource. When trying to echo or doing var_dump($ldapconn); you should see something like resource #1 - it means your connection is ready to use. If your connection failed, die() will work for sure and probably PHP warning will be thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM