Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Thu Jan 15, 2009 9:23 am Reply with quote

I have a checkbox where I can change the authentication from MySQL to LDAP.

The function ldap_auth sends them to ldap_connect_ex to make the connection to ldap.

If I have multiple ldap servers then what would be the proper way to test for each.

This is the way it is written with just one ldap_host.

Code:
function ldap_connect_ex() {

    global $CBT_config;

    $connection  = ldap_connect($CBT_config['ldap_host'], $CBT_config['ldap_port']);
    ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

    return $connection;
}


If I also have ldap_host2 then what is the proper way to code this. I believe the return of $connection is boolean.

Would the following work or is there a better way?


Code:
$connection  = ldap_connect($CBT_config['ldap_host'], $CBT_config['ldap_port']);

    if ($connection == false) {
    $connection  = ldap_connect($CBT_config['ldap_host2'], $CBT_config['ldap_port']);
    }


or..

Code:
$connection  = ((ldap_connect($CBT_config['ldap_host'])) || (ldap_connect($CBT_config['ldap_host2'])));


If ldap_host is an actual url such as [ Only registered users can see links on this board! Get registered or login! ] i have read that I don't need to include the ldap_port.

What would be the better way of checking both values?

ldap_host and ldap_host2
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Jan 15, 2009 11:43 pm Reply with quote

I've never had to program for ldap so I'm shooting in the dark. It seems that either way would work (may need a little tweaking) but you will throw an exception if it can't connect. So, try placing an '@' sign before the ldap_connect (@ldap_connect) to supress the warning/error.
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©