I’ve taken over an event website, and am mostly using the last person’s code but I wanted to add an LDAP lookup to check whether or not people (who are logged in on one system) exist on a separate LDAP list…I thought I needed to check groups initially, but actually it really is just existing. I’m sure I’m doing something obviously wrong, as I say, I’m a PHP idiot.
So they’ve logged in (I have a .htaccess set but the list of members seems to be too big to just dump all the usernames into that) so: login = $_SERVER[‘REMOTE_USER’} - on the general system, then check against the ldap code:
[php]
userlogin = $_SERVER[‘REMOTE_USER’};
//connect to LDAP list
function &connect_to_ldap(){
$ldapport = 389;
$ds = ldap_connect("OURLDAPSERVER") or die("Could not connect to LDAP server.");
if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
echo "Failed to set protocol version to 3";
return false;
} else {
return $ds;
}
}
$ds = "OURLDAPSERVER";
$dn = "dc=some,dc=site,dc=co,dc=uk,cn=users";
$filter = "(uid=$userlogin)";
$sr = ldap_search($ds, $dn, $filter);
$info = ldap_count_entries($ds, $sr);
if ($info !=1)
{
echo "$userlogin Error processing username -- if you're a member, please try to login again.";
redirect("../index.html");
exit;
}
[/php]
Any advice would be really appreciated