anner Posted October 25, 2006 Share Posted October 25, 2006 I have a bunch of code (40+ scripts) for an admin interface, many of which perform ldap searches, adds, and/or modifies. All need to bind to the same server with the same ID, so I tried putting the connection into and included file:[code]function open_ldap_conn() {$host = get_my_host();if (strstr($host,"test")) { $ldapServer = "test.ldap.server";}else { $ldapServer = "live.ldap.server"; }//try and connect to ldap server$ds = ldap_connect($ldapServer);if (!$ds) {die('Cannot Connect to LDAP server');}$domadlogin = "cn=admin";$domadpw = "mypass";//bind to ldap server$ldapBind = ldap_bind($ds,$domadlogin,$domadpw);if (!$ldapBind) {die('Cannot Bind to LDAP server');}return($ds);}[/code]Now, it appears to be executing the included code without issue, but when I try and us the connection it fails:[code]//Check for list existance$ds = open_ldap_conn();$Base = "ou=whitepages,o=my_o,c=us";list($List, $dummy) = split("@",$ListName);$Filter = "(cn=$List)"; # LDAP search filter$sr = ldap_search($ds,$Base,$Filter);if (!$sr) {log_error("List duplicate check failed<br>", 1); return(1);}if (ldap_first_entry($ds, $sr)) { ncmail_log_error("A list already exists with this name. Please choose a new name for your list.<br>", 1); return(1); }[/code]With error:warning: ldap_search(): supplied argument is not a valid ldap link resourceand my output: List duplicate check failedIs it not possible to do this? It seems silly to have to include the code for the connect in more than 40 different places when it's the exactly the same code over and over. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.