PHP Classes

File: create_random_contacts.php

Recommend this page to a friend!
  Classes of Michele Brodoloni   LDAP Address Book   create_random_contacts.php   Download  
File: create_random_contacts.php
Role: Example script
Content type: text/plain
Description: Sample script. Creates random contacts in the addressbook.
Class: LDAP Address Book
Manage contacts stored on an LDAP server
Author: By
Last change: php-cli
Date: 17 years ago
Size: 1,082 bytes
 

Contents

Class file image Download
<?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();

?>