well i was expirmenting with this a while to make a security image, and maybe i should post it in the snippet section but here it is
Code: Select all
function arraygen($length){
$letters = array('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');
$numbers = array('0','1','2','3','4','5','6','7','8','9');
srand((double)microtime()*1000000);
for($index = 0; $index < $length; $index++){
for($i = 1; $i < 9; $i++)
{
$rand = mt_rand(1,2);
if($rand == 1)
{
$q = mt_rand(1,26);
$char[$i] = $letters[$q];
}
if($rand == 2)
{
$q = mt_rand(1,10);
$char[$i] = $numbers[$q];
}
}
$array[$index] = "_ ".$char[1]." ".$char[2]." ".$char[3]." ".$char[4]." ".$char[5]." ".$char[6]." ".$char[7]." ".$char[8];
}
return $array;
}
srand((double)microtime()*1000000);
$rand = mt_rand(1, 100);
$array = arraygen($rand);
$string = $array[mt_rand(1, $rand)];
$stringpieces = explode(" ", $string);
$_SESSION['secret_string'] = $stringpieces[1].$stringpieces[2].$stringpieces[3].$stringpieces[4].$stringpieces[5].$stringpieces[6].$stringpieces[7].$stringpieces[8];
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Pragma: no-cache");
header("Content-type: image/png");
$img_handle = imagecreatefrompng("secure.png");
$back_color = ImageColorAllocate ($img_handle, 64, 131, 183);
for ($i = 1; $i < 9;$i++) {
ImageTTFText ($img_handle, mt_rand(10,20) / 96 * 72, 0, 15 * $i, 18, ImageColorAllocate ($img_handle, 255, 255, 255), dirname( __FILE__ )."/verdana.ttf", $stringpieces[$i]);
}
Imagepng($img_handle);