3 * This example shows how you might store user data directly into AD.
4 * AD has several attributes you can use for storing your own data, and
7 * This is only the beginning code,
11 $host = ""; // for eg "1.2.3.4"
12 $binduser = ""; // for eg "administrator"
13 $bindpass = ""; // for eg "password"
14 $basecn = ""; // for eg "CN=users, DC=google, dc=com"
16 //require our GoogleAuthenticator sub classed class
17 require_once("extend.php");
20 // this is here so i can keep my atributes somewhere in the tree and not have them float around on git/svn
21 if(file_exists("../../../../.dontappearingitandsvn.php")) require_once("../../../../.dontappearingitandsvn.php");
25 // first, lets bind our AD with out management creds
26 error_log("host is $host");
27 $dsconnect = ldap_connect("$host", 389);
29 // we mark it global so we can get it in our class
30 global $dsconnect, $host, $binduser, $bindpass, $basecn;
34 $errorText = "Can't Connect to AD";
36 $ldapbind = ldap_bind($dsconnect, "$binduser", "$bindpass");
39 <H1>Welcome to GA4PHP Talking to Active Directory</H1>
43 echo "<font color=\"red\">$errorText</font><br>";
47 Our user list within AD:
49 <tr><th>Name</th><th>Login Name</th></tr>
51 $sr = ldap_search($dsconnect, "$basecn", "objectclass=user");
52 $info = ldap_get_entries($dsconnect, $sr);
53 //$info["extensionattribute2"] = "-----";
58 foreach($info as $key => $val) {
59 //echo "$key is ".$val["distinguishedname"][0]."\n";
60 if($val["distinguishedname"][0] != "") {
61 $user[$i]["dn"] = $val["distinguishedname"][0];
62 $user[$i]["acn"] = $val["samaccountname"][0];
63 $user[$i]["cn"] = $val["cn"][0];
70 foreach($user as $value) {
73 echo "<tr><td>$cn</td><td>$un</td></tr>";
80 testing administrator<br>
82 if($myga->hasToken("administrator")) {
83 echo "administrator has a token<br>";
85 echo "administrator has no token, setting one<br>";
86 $myga->setUser("administrator");