Jump to content

Getting Info from Active Directories.


iPixel

Recommended Posts

Ok so i managed to connect and bind to my LDAP server for my Active Directory.

 

The heck do i do now? How to i pull information from specific areas, is there a way for me to list all the tables/containers so i know what to pull the info from?

 

My first obstacle is authenticating a user logon. But i have ZERO clue as to what these CN, DN, OU's are... any help would be fantastic.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/153186-getting-info-from-active-directories/
Share on other sites

Ok I've made some progress, but for some reason my username is having trouble binding to the LDAP. Can anyone just overlook the code and see if i have any noob mistakes in it?.

 

<?php
$server="ny-domain.com"; //change to ip address of ldap server
$basedn="dn=Department, dn=State, dn=Corporate, dn=Company, dn=com"; //change to reflect the ou and domain that your users are in.
        
if ((isset($_POST['username'])) && (isset($_POST['password']))) 
{

	$username=$_POST['username'];
	$password=$_POST['password'];

	$filter="(&(|(!(displayname=Administrator*))(!(displayname=Admin*)))(cn=$username))";        
	//define an appropriate ldap search filter to find your users, 
	//and filter out accounts such as administrator(administrator should be renamed anyway!).

	$dn = "cn=$username, "; // this is where i have trouble.
	if (!($connect = ldap_connect($server))) 
		{
			die ("Could not connect to LDAP server");
		}
	else
		{
			echo "Connected to LDAP <br>";
		}

	if (!($bind = ldap_bind($connect, "$dn", $basedn, $password))) 
		{
			die ("Could not bind to $dn");
		}
	else
		{
			echo "Grats $username, you are now binded to the LDAP server";
		}

	$sr = ldap_search($connect, $basedn, "$filter");

	$info = ldap_get_entries($connect, $sr);

	$fullname=$info[0]["displayname"][0];

	$fqdn=$info[0]["dn"];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.