Login   Register  
PHP Classes
elePHPant
Icontem

File: create_random_contacts.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2007-06-07 00:46
Size: 1,082 bytes
 

Contents

Class file image Download
<?php
//---[ Author: Michele Brodoloni (michele@xtnet.it)
//---[ 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("test@test.com");
            
$ldap->create_entry($n++, $word$word$mail);
        }
    }
    
$ldap->disconnect();

?>