Solved

PHP issues with ldaps://

Posted on 2007-04-11
6
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

623 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