T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 1
  Today Visit: 304
  Total Visitor : 301326
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

Random ID Strings

Author : DigitaLink

Works best as an include file. The functions will return a string of random characters of any specified length. You choose upper&lowercase letters and numbers, numbers only, upper&lowercase letters only, or lowercase letters only. Also includes a function to create anti-robot images if you have a directory with images in it. (named a.gif, b.gif, etc.) You need upper and lowercase images and number images. Very handy for user sign-ups!

PHP Example :

<?php
  
function assign_rand_value($num$alphanums) {
      
// accepts 1 - 62 (1-52 alpha, 53-62 numeric)
        
$rand_value $alphanums[$num];
      return 
$rand_value;
  }
  
  function 
get_rand_id($length) { // ID is letters and numbers
        
$alphanum = 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""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""0""1""2""3""4""5""6""7""8""9");
    if(
$length>0) { 
        
$rand_id="";
        for(
$i=1$i<=$length$i++) {
            
mt_srand((double)microtime() * 1000000);
            
$num mt_rand(1,62);
            
$rand_id .= assign_rand_value($num$alphanum);
        }
    }
      return 
$rand_id;
  }
  
  function 
get_rand_numbers($length) { // ID is numbers only
        
$alphanum = 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""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""0""1""2""3""4""5""6""7""8""9");
    if(
$length>0) { 
        
$rand_id="";
         for(
$i=1$i<=$length$i++) {
             
mt_srand((double)microtime() * 1000000);
             
$num mt_rand(53,62);
             
$rand_id .= assign_rand_value($num$alphanum);
         }
    }
      return 
$rand_id;
  }
  

  function 
get_rand_letters($length) {
        
$alphanum = 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""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""0""1""2""3""4""5""6""7""8""9");
    if(
$length>0) { 
        
$rand_id="";
         for(
$i=1$i<=$length$i++) {
             
mt_srand((double)microtime() * 1000000);
             
$num mt_rand(1,52);
             
$rand_id .= assign_rand_value($num$alphanum);
         }
    }
      return 
$rand_id;
  }

  function 
get_rand_lower($length) {
        
$alphanum = 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""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""0""1""2""3""4""5""6""7""8""9");
    if(
$length>0) { 
        
$rand_id="";
         for(
$i=1$i<=$length$i++) {
             
mt_srand((double)microtime() * 1000000);
             
$num mt_rand(1,26);
             
$rand_id .= assign_rand_value($num$alphanum);
         }
    }
      return 
$rand_id;
  }

    function 
anti_bot_image($key) {
        
$size strlen($key);
        for (
$i=0$i<$size$i++) { // put each letter in an array
            
$keyArray[$i] = $key{$i};
        }
        foreach (
$keyArray as $imgLetter) { // get each letter's image in array
            
$imgArray[] = "<img src='";
            
$imgArray[] = $DOCUMENT_ROOT."/images/".$imgLetter.".gif";
            
$imgArray[] = "' title='";
            
$imgArray[] = $imgLetter."'>";
        }
        
$displayCode implode(""$imgArray);
        return 
$displayCode;
    }
?>


Other Example
Random Text State
Random Picture Display


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007