Web Analytics Made Easy -
StatCounter making random string - CodingForum

Announcement

Collapse
No announcement yet.

making random string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • making random string

    to all,
    is there an in built function in php that cna generate a random string? example:

    rand() are for generating numbers right?

    so what is the function for generating a string?what i mean of string is like probably---> fsr45mdk43 or something like that.

    pls help..thanking u in advance.
    Warm Regards,
    Mivec

  • #2
    I used to have quite a nice way of making a random string but I have forgotten it. I think it used rand though.

    This is how invisionboard generate a random password

    PHP Code:
        function make_password()
        {
            
    $pass "";
            
    $chars = array(
                
    "1","2","3","4","5","6","7","8","9","0",
                
    "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
                
    "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
                
    "u","U","v","V","w","W","x","X","y","Y","z","Z");
        
            
    $count count($chars) - 1;
        
            
    srand((double)microtime()*1000000);

            for(
    $i 0$i 8$i++)
            {
                
    $pass .= $chars[rand(0$count)];
            }
        
            return(
    $pass);
        } 
    you could obviously change the length and function name. Also, i think the (double) method is no longer used so, you could replace:

    PHP Code:

    srand
    ((double)microtime()*1000000)

    with:

    $microtime microtime()*1000000;
    settype($microtime'float');
    srand($microtime); 
    PHP Weekly - A PHP Developers Resource
    PHP 5.1.4 and Ruby on Rails web hosting
    Moderator of PHP and Work offers and Requests
    Install Apache/PHP/MySQL
    (by marek_mar) | TinyPlugin Architecture

    Comment


    • #3
      this link may help you. ( http://www.phpnoise.com/tutorials/1/2 )
      on this site is uses $string = md5(rand(0,9999));
      I have tried it out and it works. you just have to use substr($string,start#,end#); to get the desired string length.
      eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

      Comment

      Working...
      X