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: 15 years ago
Size: 1,082 bytes


Class file image Download
//---[ Author: Michele Brodoloni (
//---[ Creates N random contacts into an LDAP-based addressbook
//---[ This script is for php-cli. Use it with php -q <script_name>


//---[ Contact's name lenght
    if ( (
$argc != 2) || (!is_numeric($argv[1])) )
"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 (
//---[ 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("");
$ldap->create_entry($n++, $word, $word, $mail);