"Fossies" - the Fresh Open Source Software Archive

Member "adLDAP-4.0.4/examples/examples.php" (13 Apr 2013, 3081 Bytes) of package /linux/www/old/adLDAP-4.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?
    2 /*
    3 Examples file
    4 
    5 To test any of the functions, just change the 0 to a 1.
    6 */
    7 
    8 //error_reporting(E_ALL ^ E_NOTICE);
    9 
   10 include (dirname(__FILE__) . "/../src/adLDAP.php");
   11 try {
   12     $adldap = new adLDAP($options);
   13 }
   14 catch (adLDAPException $e) {
   15     echo $e;
   16     exit();   
   17 }
   18 //var_dump($ldap);
   19 
   20 echo ("<pre>\n");
   21 
   22 // authenticate a username/password
   23 if (0) {
   24     $result = $adldap->authenticate("username", "password");
   25     var_dump($result);
   26 }
   27 
   28 // add a group to a group
   29 if (0) {
   30     $result = $adldap->group()->addGroup("Parent Group Name", "Child Group Name");
   31     var_dump($result);
   32 }
   33 
   34 // add a user to a group
   35 if (0) {
   36     $result = $adldap->group()->addUser("Group Name", "username");
   37     var_dump($result);
   38 }
   39 
   40 // create a group
   41 if (0) {
   42     $attributes=array(
   43         "group_name"=>"Test Group",
   44         "description"=>"Just Testing",
   45         "container"=>array("Groups","A Container"),
   46     );
   47     $result = $adldap->group()->create($attributes);
   48     var_dump($result);
   49 }
   50 
   51 // retrieve information about a group
   52 if (0) {
   53     // Raw data array returned
   54     $result = $adldap->group()->info("Group Name");
   55     var_dump($result);
   56 }
   57 
   58 // create a user account
   59 if (0) {
   60     $attributes=array(
   61         "username"=>"freds",
   62         "logon_name"=>"freds@mydomain.local",
   63         "firstname"=>"Fred",
   64         "surname"=>"Smith",
   65         "company"=>"My Company",
   66         "department"=>"My Department",
   67         "email"=>"freds@mydomain.local",
   68         "container"=>array("Container Parent","Container Child"),
   69         "enabled"=>1,
   70         "password"=>"Password123",
   71     );
   72     
   73     try {
   74         $result = $adldap->user()->create($attributes);
   75         var_dump($result);
   76     }
   77     catch (adLDAPException $e) {
   78         echo $e;
   79         exit();   
   80     }
   81 }
   82 
   83 // retrieve the group membership for a user
   84 if (0) {
   85     $result = $adldap->user()->groups("username");
   86     print_r($result);
   87 }
   88 
   89 // retrieve information about a user
   90 if (0) {
   91     // Raw data array returned
   92     $result = $adldap->user()->info("username");
   93     print_r($result);
   94 }
   95 
   96 // check if a user is a member of a group
   97 if (0) {
   98     $result = $adldap->user()->inGroup("username","Group Name");
   99     var_dump($result);
  100 }
  101 
  102 // modify a user account (this example will set "user must change password at next logon")
  103 if (0) {
  104     $attributes=array(
  105         "change_password"=>1,
  106     );
  107     $result = $adldap->user()->modify("username",$attributes);
  108     var_dump($result);
  109 }
  110 
  111 // change the password of a user. It must meet your domain's password policy
  112 if (0) {
  113     try {
  114         $result = $adldap->user()->password("username","Password123");
  115         var_dump($result);
  116     }
  117     catch (adLDAPException $e) {
  118         echo $e; 
  119         exit();   
  120     }
  121 }
  122 
  123 // see a user's last logon time
  124 if (0) {
  125     try {
  126         $result = $adldap->user()->getLastLogon("username");
  127         var_dump(date('Y-m-d H:i:s', $result));
  128     }
  129     catch (adLDAPException $e) {
  130         echo $e; 
  131         exit();   
  132     }
  133 }
  134 
  135 // list the contents of the Users OU
  136 if (0) {
  137     $result=$adldap->folder()->listing(array('Users'), adLDAP::ADLDAP_FOLDER, false);
  138     var_dump ($result);   
  139 }
  140 ?>