Here is how you use NT Authentication with LDAP servers. This is coming from a Windows Server 2003 and tried on a Windows Server 2000 LDAP server.
The host is a Windows XP, Apache, PHP 4.3.9 Machine. Also tried on a Windows Server 2003, IIS 6, PHP 4.3.9 Machine. Somethings were taken out for security reasons. Sorry.
Hope this helps!
Chad
//
// This page is index.php
//
<?php
session_start();
if(isset($login)){
$username = trim($username);
$password = trim($password);
if((strlen(trim($username)) != 0) && (strlen(trim($password)) != 0))
{
include_once("includes/ldap.connection.inc.php");
// Run the CheckNT function.
$checked = CheckNT($username,$password);
// Get the results. If it is in the LDAP server it returns 1. If not then 0.
if($checked == 1)
{
include_once("includes/db.connection.inc.php");
$sql = "SELECT * FROM smithch.users WHERE user_name='$username'";
$result = mssql_query ($sql, $db);
$row = mssql_num_rows ($result);
if($row < 1)
{
echo "Sorry you are authenticated but not part of our database system. Sorry.<br>";
}
while ($row = mssql_fetch_array($result))
{
$user_id = $row['user_id'];
$user_priv = $row['user_priv'];
$user_divnum = $row['user_divnum'];
$user_style = $row['user_style'];
$_SESSION['GLOBAL_ID'] = "$user_id";
$_SESSION['GLOBAL_NAME'] = "$username";
$_SESSION['GLOBAL_PRIV'] = "$user_priv";
$_SESSION['GLOBAL_DIVNUM'] = "$user_divnum";
$_SESSION['GLOBAL_STYLE'] = "$user_style";
$today = date("F j, Y, g:i a");
$update_users = "UPDATE smithch.users SET user_lastlogin='$today' WHERE (user_id = '$user_id')";
mssql_query($update_users);
echo "<meta http-equiv='refresh' content='0; URL=dbsystem.index.php'>";
exit();
}
mssql_close($db);
}else{
echo "Your credentials failed. Check your password and try again. Also no NRDNR\\\ is nesscary.<br>";
}
}else{
echo "All fields <strong>MUST</strong> be filled in. Thanks!";
}
}
?>
//
// This page is ldap.connection.inc.php
//
<?php
error_reporting(E_ERROR | E_PARSE);
// Functions
function CheckNT($username,$password)
{
// Forms the USERNAME as NRDNR\\
$domain_username = "NRDNR\\" . $username;
// Connects to our LDAP server.
$ldapconn=ldap_connect("valid_ip_of_server") or die("The connection failed.");
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $domain_username, $password);
// verify binding
if ($ldapbind) {
return 1;
} else {
return 0;
}
ldap_close($ds);
}
?>