PDA

View Full Version : تولید کننده ی رشته ی تصادفی یونیک



blackmak
پنج شنبه 28 مهر 1390, 16:46 عصر
یه اسکریپت مطمئن برای تولید رشته تصادفی 32 کاراکتری قبلا نوشته بودم برای نامگذاری فایلهای آپلودی خوبه . شاید بدرد کسی خورد


<?php
class random_string
{
private $i=1;
private $rand_c='';
private $rand_n='';
private $array = array ("0","1","2","3","4","5","6","7","8","9","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");
public function rand_char($length=32)
{
for($this->i ; $this->i <= $length ; $this->i++ )
{
$this->rand_n = array_rand( $this->array );
$this->rand_c = $this->rand_c.$this->array[$this->rand_n];
}
$this->rand_c = md5('Siamak'.$this->rand_c.uniqid().'A');
return($this->rand_c);
}
}
$random_string = new random_string();
$rand_str = $random_string->rand_char();
echo $rand_str;
?>