/    Sign up×
Community /Pin to ProfileBookmark

PHP and Active Directory ( ldap )

Hello all, I have more of a general question (maybe “best practices” would be better) instead of a specific code question.

I would like to export my users username and password for domain logon to my sql tables.

I have a column for username and password on my contacts table that allows access rights to various pages and applications. Works great, except for all the belly achen’ about having to recall yet another password. Now in a perfect world I would just do a nightly import from AD to my contacts table. However, I assume there are some pit-falls with this approach. Anyone have some insight?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@PineSolPirateAug 03.2006 — I realize this isn't an answer to what you asked, but maybe it will help anyway.

I'm not certain about authentication, but I know we have ssl and secure logons to our intranet, using windows authentication. We just use $_SERVER[AUTH_USER] to get at who logs in and put that against a table of auth users for areas.

I doubt you want to go through all your scripts and mess with them though ?
Copy linkTweet thisAlerts:
@Doc_ThirstauthorAug 03.2006 — Hey, any reply is a good reply, I was scared this post would fall flat. Thanks for the bone.
Copy linkTweet thisAlerts:
@PineSolPirateAug 03.2006 — K, I poked around our old server because I remembered seeing a file with ldap in it. This was a handme down, I honestly have no idea how it works, but it seems to work. Don't ever use it though, can't even test it actually. Hope it helps.
[code=php]<?php
ldap_get_info("user","password");
function ldap_get_info($user, $pass) {
// Get name value to search for from submitted form.

$ldap_server = "arrowhead";
$auth_user = "$user" . "@domain.com";
$auth_pass = "$pass";

// Set the base dn to search the entire microsoft.com directory.

$base_dn = "DC=each, DC=dotted, DC=section, DC=com";

/* filter the search for all people in the microsoft.com tree that have a
name that matches any one of the following attributes name, displayname, or cn. */

// connect to server

if (!($connect=@ldap_connect($ldap_server))) {
die("Could not connect to ldap server :: $ldap_server");
}

// bind to server

if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) {
die("Unable to bind to server for $user");
}

//$filter = "cn=*$user*";

$filter="(sAMAccountName=$user)";

// search active directory
if (!($search=@ldap_search($connect, $base_dn, $filter))) {
print "$filter<br>";
var_dump($search); print "<br>";
var_dump(ldap_error($connect));print "<br>";
var_dump(ldap_errno($connect));print "<br>";
die("Unable to search ldap server");

}


$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);

//echo "The number of entries returned is ". $number_returned;

for ($i=0; $i<$info["count"]; $i++) {
//echo "Name is: ". $info[$i]["name"];
//echo "Display name is: ". $info[$i]["displayname"][0];
//echo "Email is: ". $info[$i]["mail"][0];
//echo "Telephone number is: ". $info[$i]["telephonenumber"][0];
$myinfo[name] = $info[$i]["name"];
$myinfo[displayname] = $info[$i]["displayname"][0];
$myinfo[email] = $info[$i]["mail"][0];
$myinfo[telephonenumber] = $info[$i]["telephonenumber"][0];

}
print "<pre>";
print_r($myinfo);
print "</pre>";

}

?>[/code]
Copy linkTweet thisAlerts:
@Doc_ThirstauthorAug 03.2006 — Awesome, let me fire it up and see how it fares.
×

Success!

Help @Doc_Thirst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...