Solved

PHP issues with ldaps://

Posted on 2007-04-11
6
848 Views
Last Modified: 2013-12-20
I'm having issues connecting to an ldaps:// server with PHP 5.2.0. I was able to successfully write code in perl and connect to the same server from the same source machine without any issues. Perhaps I'm overlooking an option here. On the LDAP side, I'm using OpenLDAP 2.3.30. I'm currently allowing anonymous binds, and just to verify, ldapsearch works just fine as well without any additional arguments.

The following is the PHP warning, a Protocol error:

Apr 11 14:55:29 host httpd: PHP Warning:  ldap_bind() [<a href='function.ldap-bind'>function.ldap-bind</a>]: Unable to bind to server: Protocol error in /www/host.foo.com/changepass.php on line 72

code excerpt:

function ldap_init() {
  $ldaphost = "ldaps://host.foo.com:636/";
  //$ldapport = '636';
  ldap_set_option($ldaphost, LDAP_OPT_REFERRALS, 0);
  echo "Initiating LDAP query...<br>";
  $ldapconn = ldap_connect($ldaphost)
     or die("Could not connect to $ldaphost");

  if($ldapconn) {
     echo "Initialization successful. Let's bind to the directory.<br>";
     $ldapbind = ldap_bind($ldapconn); // This is an anonymous bind
     if (!ldap_bind($ldapconn)) {
        echo "Error: " . ldap_error($ldapconn);
     }
  }
}

Thanks to anyone who can lend a helping hand. :-)
0
Comment
Question by:stevefNYC
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 18892291
I cannot teszt it but try:

function ldap_init() {
  $ldaphost = "ldaps://host.foo.com";
  $ldapport = '636';
$ldapconn = ldap_connect($ldaphost, $ldapport)
     or die("Could not connect to $ldaphost");
  ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
  echo "Initiating LDAP query...<br>";
    if($ldapconn) {
     echo "Initialization successful. Let's bind to the directory.<br>";
     $ldapbind = ldap_bind($ldapconn); // This is an anonymous bind
     if (!ldap_bind($ldapconn)) {
        echo "Error: " . ldap_error($ldapconn);
     }
  }
}
0
 
LVL 3

Author Comment

by:stevefNYC
ID: 18892342
No go, I tried the above also.. as you can see I had $ldapport commented out above from prior testing. By the way, I made sure to compile PHP with OpenSSL support.

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 18892384
While googling i found users had problem while using dns name. did you try using IP?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Accepted Solution

by:
netmunky earned 500 total points
ID: 18892495
have you tried LDAP_OPT_PROTOCOL_VERSION?

http://php.osuosl.org/manual/en/function.ldap-bind.php#72795
0
 
LVL 3

Author Comment

by:stevefNYC
ID: 18892514
Aye, I've tried by IP also, apologies for not mentioning that. I've also ran tcpdump on the LDAP server and I see packets hitting the interface on tcp/636, so it's something to do with SSL in specific I'd imagine.
0
 
LVL 3

Author Comment

by:stevefNYC
ID: 18892583
awesome netmunky. That did it. I was setting LDAP_OPT_PROTOCOL_VERSION, but misread the documentation and was setting it prior to ldap_connect(). I moved the code to after the connect and all looks OKAY now.

Thank you kindly for your assistance!
0

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!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

743 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

12 Experts available now in Live!

Get 1:1 Help Now