We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

javierarce on 09/07/06


Tagged

textmate random unique md5 uniqid


Versions (?)


Who likes this?

7 people have marked this snippet as a favorite

Roshambo
NexusRex
mdavie
blakeb
vali29
Nix
pixelhandler


Generate Random String


Published in: PHP 


Generates a random string of variable length.

  1. function getUniqueCode($length = "")
  2. {
  3. $code = md5(uniqid(rand(), true));
  4. if ($length != "") return substr($code, 0, $length);
  5. else return $code;
  6. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: KyleFarris on October 23, 2008

Very useful. Thanks.

You need to login to post a comment.