How to list users in php active directory
How can I list, group users in the PHP active directory? Will there be any problems when listing it,if so how to overcome those problems and list the users in the PHP active directory?
How can I list, group users in the PHP active directory? Will there be any problems when listing it,if so how to overcome those problems and list the users in the PHP active directory?
Hi,
This is very easy task. It works well, and you can use it. As this code is just pieced together, so you need to edit it to your own server.
Just as an aside to the above code, it's very crude and just pieced together. You need to alter it to your own server and it needs some security features adding to it (Add slashes) to stop malicious code. You can use the functions to check if the user credentials are correct against the LDAP DIRS.
Enter: group name, user name and password in the parameters of function.
<? PHP
    // Get vars from post
    $username = $_POST['username'];
    $password = $_POST['password'];
    // Open the connection
    $ad = ldap_connect("ldap server") or
          Die ("Couldn't connect to AD!"); // ldap: //servername
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION,3);
    ldap_set_option($ad, LDAP_OPT_REFERRALS,0);
    $bd = ldap_bind($ad,$username,$password)
      or die("Couldn't bind to AD!");
    // Do stuff
    // Create the DN
    $dn = "full ldap dn for AD"; // CN=foo,OU=bar etc…
   Â
    // Create the filter from the search parameters
    $filter = "(&(&(&(objectCategory=person)(objectClass=user))))"; Select all users
   Â
    $search = @ldap_search($ad, $dn, $filter)
              or die ("ldap search failed");
   Â
    $entries = ldap_get_entries($ad, $search);
   Â
    if ($entries["count"] > 0)
        {
            for ($i=0; $i<$entries["count"]; $i++)
                {
                    echo "<p>Name: ".$entries[$i]["displayname"][0]."<br />";
                    echo "Email: ".$entries[$i]["mail"][0]."<br />";
                    echo "Username: ".$entries[$i]["samaccountname"] [0]."<br />";
                    echo "Username: ".$entries[$i]["logoncount"] [0]."<br />";
                    echo "DN: ". $entries [$i] ["distinguished name"] [0]."</p>";
                }
        }
    else
        {
            echo "<p>No results found!</p>";
        }
   Â
    // Modify locked out
    //ldap_modify ( $ad, "" , array $entry )
        // Close the connection
        ldap_unbind($ad);
?>
Hi Dafadilia,
Thanks for your question.
To list users in PHP directory, you have to follow the following steps-
First of all-//create a path to directory to scan. $directory = "../images/team/harry/"; Â Then- //get all your files with a .JPG extension. $images = glob($directory . "*. JPG"); Â And then- //print each file name foreach ($images as $image) {Echo $image;}
Note:You can use any files.Above example is for JPG files. If you have word docs, then replace JPG of text.
For security reason, never trust any foreign add ons. View security information at The Open Web Application Security Project
You can get more information from php.net
Hope you can do this now.Â
Thank you.