| 
<?php
//---[ Author: Michele Brodoloni ([email protected])
 //---[ Creates N random contacts into an LDAP-based addressbook
 //---[ This script is for php-cli. Use it with php -q <script_name>
 
 require("ldap_addressbook.class.php");
 
 //---[ Contact's name lenght
 $LEN=8;
 
 if ( ($argc != 2) || (!is_numeric($argv[1])) )
 die("Usage: ". $argv[0] ." <number of contacts>\n");
 
 $alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
 
 $ldap = new LDAP_addressBook("my.ldap.server","cn=admin","dc=example, dc=com","my_ldap_secret");
 
 if ($ldap->connect())
 {
 //---[ Random words generation
 for ($i=0; $i<$argv[1]; $i++)
 {
 $word = '';
 //---[ Concatenating letters
 for($j=0; $j<$LEN; $j++)
 {
 $index = rand(0,count($alpha));
 $word .= $alpha[$index];
 }
 
 //            echo ("$i: $word\n");
 $mail = array("[email protected]");
 $ldap->create_entry($n++, $word, $word, $mail);
 }
 }
 $ldap->disconnect();
 
 ?>
 
 |