Hi All,
I have this code to authenticate users on an active directory server and then query a table on my database that contains their user level. For some reason I am not getting any records returned when I run the query in my script but if I run it directly in MySQL i get back the expected record. In my troubleshooting I am getting the dreaded "mysql_fetch_array() expects parameter 1 to be resource, boolean given..".
Here is the script:
I am sure there is something simple I am overlooking. Thanks in advance for your help.
Kind regards,
Ken
I have this code to authenticate users on an active directory server and then query a table on my database that contains their user level. For some reason I am not getting any records returned when I run the query in my script but if I run it directly in MySQL i get back the expected record. In my troubleshooting I am getting the dreaded "mysql_fetch_array() expects parameter 1 to be resource, boolean given..".
Here is the script:
PHP:
<?php require_once("connection.php"); ?>
<?php
function authenticate($user, $password) {
// Active Directory server
$ldap_host = "My-AD-Server";
// Active Directory port
$ldap_port = 389;
// connect to active directory
$ldap = ldap_connect($ldap_host, $ldap_port);
// verify user and password
if($bind = @ldap_bind($ldap, $user, $password)) {
// valid
// check presence in groups
$strUser=mysql_real_escape_string($user);
$result=mysql_query("SELECT * FROM tblusers WHERE adUserName = '$strUser'");
if($result) {
$row=mysql_fetch_array($result);
$access=$row['userLevel'];
}else{
$access="visitor";
}
// establish session variables
$_SESSION['MM_Username'] = $user;
$_SESSION['MM_UserGroup'] = $access;
return true;
} else {
// invalid name or password
return false;
}
}
?>
<?php mysql_close($dbConnection); ?>
I am sure there is something simple I am overlooking. Thanks in advance for your help.
Kind regards,
Ken