您好,欢迎访问一九零五行业门户网

php 生成验证程序

geturifilename() == authcode.php)
{
  $authcode->outputimg();
}
}
function chkauthcode($authcode)
{
if ($_session['authcode'] == $authcode)
{
  $rtn = true;
}
else
{
  $rtn = false;
}
$_session['authcode'] = rand(0, 999999);
return $rtn;
}
class authcode
{
/* public variables */
/* private variables */
var $image;
#
var $sbgcolor;
var $nwidth;
var $nheight;
var $nlen;
var $bnoise;
var $nnoise;
var $bborder;
var $afontlist;
/* constractor */
function authcode()
{
  $this->sbgcolor = #ffcc00;
  $this->nwidth = 70;
  $this->nheight = 25;
  $this->nleftmargin = 5;
  $this->nrightmargin = 5;
  $this->ntopmargin = 3;
  $this->nbottommargin = 2;
  $this->nlen = 4;
  $this->bnoise = true;
  $this->nnoisepoint = 50;
  $this->nnoiseline = 5;
  $this->bborder = true;
$this->afontlist[0] = ./fonts/arial.ttf;
  $this->afontlist[1] = ./fonts/comic.ttf;
  $this->afontlist[2] = ./fonts/raavi.ttf;
  $this->afontlist[3] = ./fonts/verdanai.ttf;
  $this->afontlist[4] = ./fonts/tahoma.ttf;
  $this->afontlist[5] = ./fonts/shruti.ttf;
  $this->afontlist[6] = ./fonts/bkant.ttf;
  $this->afontlist[7] = ./fonts/comicbd.ttf;
  $this->afontlist[8] = ./fonts/courbi.ttf;
  $this->afontlist[9] = ./fonts/times.ttf;
}
function outputimg()
{
  $this->image = ;
  $this->image = imagecreate($this->nwidth, $this->nheight);
  $back = $this->getcolor($this->sbgcolor);
  imagefilledrectangle($this->image, 0, 0, $this->nwidth, $this->nheight, $back);
  $size = ($this->nwidth - $this->nleftmargin - $this->nrightmargin)/$this->nlen;
  if($size>($this->nheight - $this->ntopmargin - $this->nbottommargin))
   $size=$this->nheight - $this->ntopmargin - $this->nbottommargin;
$left = ($this->nwidth-$this->nlen*($size+$size/10))/2 + $this->nleftmargin;
  $code = ;
  for ($i=0; $inlen; $i++)
  {
   $randtext = rand(0, 9);
   $code .= $randtext;
   $textcolor = imagecolorallocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
   $font = $this->afontlist[rand(0,9)];//rand(1,4)..ttf;
   $randsize = rand($size-$size/10, $size+$size/10);
   $location = $left+($i*$size+$size/10);
   imagettftext($this->image, $randsize, rand(-18,18), $location, rand($size, $size+$size/5) + $this->ntopmargin, $textcolor, $font, $randtext);
  }
  if($this->bnoise == true) $this->setnoise();
  $_session['authcode'] = $code;
  $bordercolor = $this->getcolor(      );
  if($border==true) imagerectangle($this->image, 0, 0, $this->nwidth-1, $this->nheight-1, $bordercolor);
  header(expires: mon, 26 jul 1997 05:00:00 gmt); // date in the past
  header(last-modified: . gmdate(d, d m y h:i:s) . gmt); // always modified
  header(cache-control: no-store, no-cache, must-revalidate); // http/1.1
  header(cache-control: post-check=0, pre-check=0, false);
  header(cache-control: private);
  header(pragma: no-cache); // http/1.0
  header(content-type: image/png);
  imagepng($this->image);
  imagedestroy($this->image);
return $sauthcode;
}
function chkauthcode($authcode)
{
  if ($this->getauthcode() == $authcode)
  {
   $rtn = true;
  }
  else
  {
   $rtn = false;
  }
  $_session['authcode'] = rand(0, 999999);
  return $rtn;
}
function getauthcode()
{
  $x_authcode = $_session['authcode'];
  $_session['authcode'] = rand(0, 999999);
  return $x_authcode;
}
/* private functions */
function geturifilename()
{
  return substr($_server['script_name'], strrpos($_server['script_name'], '/') + 1 , strlen($_server['script_name']) - strrpos($_server['script_name'], '/'));
}
function setnoise()
{
  for ($i=0; $innoiseline; $i++){
   $randcolor = imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
   imageline($this->image, rand(0, $this->nwidth), rand(0, $this->nheight), rand(0, $this->nwidth), rand(0, $this->nheight), $randcolor);
  }
for ($i=0; $innoisepoint; $i++){
   $randcolor = imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)); 
   imagesetpixel($this->image, rand(0, $this->nwidth), rand(0, $this->nheight), $randcolor);
  }
}
function getcolor($color)
{
   $color = eregi_replace (^#,,$color);
   $r = $color[0].$color[1];
   $r = hexdec ($r);
   $b = $color[2].$color[3];
   $b = hexdec ($b);
   $g = $color[4].$color[5];
   $g = hexdec ($g);
   $color = imagecolorallocate ($this->image, $r, $b, $g);
   return $color;
}
}
?>
其它类似信息

推荐信息