+ Reply to Thread
Results 1 to 5 of 5

Thread: [snippet] Create Random Strings, PHP

  1. #1
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    [snippet] Create Random Strings, PHP

    Ok, to create a random string in php use this great code snippet I made

    PHP Code:
    <?php

    // Brandon <brandon@phpriots.com>
    // Support: http://www.phpriots.com/forums/
    // Rev 1

    // Edit Below
    $min "5"// Minimum Password Length
    $max "15"// Maximun Password Length

    ################## Don't edit bellow unless you know what you are doing ##################

    // Letter/number Array
    $useable_characters array_merge(range('A','Z'),range('a','z'),range(0,9));

    // Make the length
    $length rand($min,$max);

    $password "";

    for (
    $i 0$i $length$i++)
    {
      
    $newrand rand(0,61);
      
    $password .= $useable_characters[$newrand];
    }

    ################## Echo's the password out, or do something else with it ##################

    echo $password;
    ?>
    Any support questions can be asked here or at the phpRiots forums.
    Last edited by Brandon; 07-27-2007 at 05:35 AM.
    Thanks,
    Brandon Long

  2. #2
    YamiKaitou's Avatar
    YamiKaitou is offline x10 Elder YamiKaitou is an unknown quantity at this point
    Join Date
    Oct 2006
    Posts
    636

    Re: [snippet] Create Random Strings, PHP

    I have always hated typing out all of those letters/numbers.

    But what is the difference from that and using this? Anything?
    PHP Code:
    $useable_characters array_merge(range('A','Z'),range('a','z'),range(0,9)); 
    I use something similar to this with my captcha image
    Last edited by YamiKaitou; 07-27-2007 at 12:40 AM. Reason: typo

  3. #3
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: [snippet] Create Random Strings, PHP

    The fact that I never knew about that:drool:

    That does seem more handy though, mind if I use it?
    Thanks,
    Brandon Long

  4. #4
    YamiKaitou's Avatar
    YamiKaitou is offline x10 Elder YamiKaitou is an unknown quantity at this point
    Join Date
    Oct 2006
    Posts
    636

    Re: [snippet] Create Random Strings, PHP

    Not at all, I found out about it from someplace else. Can't remember where

  5. #5
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: [snippet] Create Random Strings, PHP

    Thanks, I updated the initial post to include that, seems to work so thanks.
    Thanks,
    Brandon Long

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. PHP / MySQL - Unescaping strings?
    By lambada in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 02-06-2008, 07:11 PM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  5. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers