Skip to content

Instantly share code, notes, and snippets.

@rririanto
Last active March 27, 2016 12:39
Show Gist options
  • Save rririanto/baae426d53cdc84cabd1 to your computer and use it in GitHub Desktop.
Save rririanto/baae426d53cdc84cabd1 to your computer and use it in GitHub Desktop.
PHP generate Random String
<?php
function create_costumer_key($length=8,$use_upper=1,$use_lower=1,$use_number=1,$use_custom=""){
$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$lower = "abcdefghijklmnopqrstuvwxyz";
$number = "0123456789";
if($use_upper){
$seed_length += 26;
$seed .= $upper;
}
if($use_lower){
$seed_length += 26;
$seed .= $lower;
}
if($use_number){
$seed_length += 10;
$seed .= $number;
}
if($use_custom){
$seed_length +=strlen($use_custom);
$seed .= $use_custom;
}
for($x=1;$x<=$length;$x++){
$password .= $seed{rand(0,$seed_length-1)};
}
return($password);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment