<?php
session_start();
$type='gif';
$width= 45;
$height= 20;
header("Content-type: p_w_picpath/".$type);
srand((double)microtime()*1000000);
if(isset($_GET['action'])){
$randval=randStr(4,$_GET['action']);
}else{
$randval=randStr(4,'');
}
if($type!='gif'&&function_exists('p_w_picpathcreatetruecolor')){
$im=@p_w_picpathcreatetruecolor($width,$height);
}else{
$im=@p_w_picpathcreate($width,$height);
}
$r=Array(225,211,255,223);
$g=Array(225,236,237,215);
$b=Array(225,236,166,125);
$key=rand(0,3);
$backColor=ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);
$borderColor=ImageColorAllocate($im,127,157,185);
$pointColor=ImageColorAllocate($im,255,170,255);
@p_w_picpathfilledrectangle($im,0,0,$width - 1,$height - 1,$backColor);
@p_w_picpathrectangle($im,0,0,$width-1,$height-1,$borderColor);
$stringColor=ImageColorAllocate($im,255,51,153);
for($i=0;$i<=100;$i++){
$pointX=rand(2,$width-2);
$pointY=rand(2,$height-2);
@p_w_picpathsetpixel($im,$pointX,$pointY,$pointColor);
}
@p_w_picpathstring($im,5,5,1,$randval,$stringColor);
$ImageFun='Image'.$type;
$ImageFun($im);
@p_w_picpathdestroy($im);
$_SESSION['CheckCode']=$randval;
function randStr($len=6,$format='ALL'){
switch($format){
case'ALL':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
case'CHAR':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break;
case'NUMBER':
$chars='0123456789'; break;
default :
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
}
$string='';
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return$string;
}