日期:2014-05-16 浏览次数:20534 次
<?php
session_start();
//set some important identfy constants
define('IDENTFY_NUM',5);
define('IDENTFY_WIDTH',75);
define('IDENTFY_HEIGT',25);
//create the random pass-phrase
$pass_phrase="";
for($i=0;$i<IDENTFY_NUM;$i++){
$pass_phrase.=chr(rand(97,122));
}
$_SESSION['pass_phrase']=sha1($pass_phrase);
$img=imagecreatetruecolor(IDENTFY_WIDTH,IDENTFY_HEIGHT);
$bg_color=imagecolorallocate($img,255,255,255);
$text_color=imagecolorallocate($img,0,0,0);
$graphic_color=imagecolorallocate($img,64,64,64);
imagefilledrectangle($img,0,0,IDENTFY_WIDTH,IDENTFY_HEIGHT,$bg_color);
//Draw random lines
for($i=0;$i<5;$i++){
imageline($img,0,rand()%IDENTFY_HEIGHT,IDENTFY_WIDTH,rand()%INDENTFY_HEIGHT,$graphic_color);
}
for($i=0;$i<50;$i++){
imagesetpixel($img,rand()%IDENTFY_WIDTH,rand()%IDENTFY_HEIGHT,$graphic_color);
}
//Draw the string
imagettftext($img,18,0,5,IDENTFY-5,$text_color,"Courier New Bold.ttf",$pass_phrase);
header("Content-type:image/png");
imagepng($img);
imagedestroy($img);
?>
for($i=0;$i<5;$i++){
imageline($img,0,rand()%IDENTFY_HEIGHT,IDENTFY_WIDTH,rand()%INDENTFY_HEIGHT,$graphic_color);
}
for($i=0;$i<50;$i++){
imagesetpixel($img,rand()%IDENTFY_WIDTH,rand()%IDENTFY_HEIGHT,$graphic_color);
}