PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I recenntly downloaded PHP LDAP CLASS FOR MANIPULATING ACTIVE DIRECTORY Version 3.3 and I got the authenticate test (the test allows you to enter a username and password in a input box and log in based on your username and password in AD)to work. I have never used this before and I am confused as to how to pull records out of AD.
<?php
$ldaprdn = 'username for ad';
$ldappass = 'password for ad';
// connect to ldap server
$ldapconn = ldap_connect("localhost")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
}
//*****I have also tried this*****
$ldapconn = ldap_connect("localhost")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding anonymously
$ldapbind = ldap_bind($ldapconn);
if ($ldapbind) {
echo "LDAP bind anonymous successful...";
} else {
echo "LDAP bind anonymous failed...";
}
}
?>
As of right now I cant even get past the binding. I an error that states Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in C:\index.php on line 11
LDAP bind anonymous failed...
I am usig xampp if that matters. Any help on this issue would be more than greatly apprieciated
even when I changed the name of the Ldap server it would not bind im using xampp if that has anything to do with it....is it possible however, to go from that sort of a login and connect it to a page using no ldap connections at all? I figured what I could do is have the user log in so they didnt have to register a new password but pull their information out of a MySQL database based on the users username. here is what i have in both scripts
<?php
//log them out
$logout=$_GET['logout'];
if ($logout=="yes"){ //destroy the session
session_start();
$_SESSION = array();
session_destroy();
}
//force the browser to use ssl (STRONGLY RECOMMENDED!!!!!!!!)
if ($_SERVER["SERVER_PORT"]!=443){ header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); exit(); }
//you should look into using PECL filter or some form of filtering here for POST variables
$username=strtoupper($_POST["username"]); //remove case sensitivity on the username
$password=$_POST["password"];
$formage=$_POST["formage"];
if ($_POST["oldform"]){ //prevent null bind
if ($username!=NULL && $password!=NULL){
//include the class and create a connection
include ("../adLDAP.php");
try {
$adldap = new adLDAP();
}
catch (adLDAPException $e) {
echo $e; exit();
}
//authenticate the user
if ($adldap -> authenticate($username,$password)){
//establish your session and redirect
session_start();
$_SESSION["username"]=$username;
$redir="Location: https://".$_SERVER['HTTP_HOST']."/gotofile.php";
header($redir);
//echo $username;
exit;
}
}
$failed=1;
}
?>
<html>
<head>
<title>adLDAP example</title>
</head>
<body>
This area is restricted.<br>
Please login to continue.<br>
<form method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'>
<input type='hidden' name='oldform' value='1'>
Username: <input type='text' name='username' value='<?php echo ($username); ?>'><br>
Password: <input type='password' name='password'><br>
<br>
<input type='submit' name='submit' value='Submit'><br>
<?php if ($failed){ echo ("<br>Login Failed!<br><br>\n"); } ?>
</form>
<?php if ($logout=="yes") { echo ("<br>You have successfully logged out."); } ?>
</body>
</html>