Location: PHPKode > projects > Spam free PHP GuestBook > Spam free PHP GuestBook-1.2beta/gb/verify/securityimage.php
<?php
/*
Copyright (c) 2008 ramui.com. All right reserved.
This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.
*/
class verification
{

private function verificationcode($s)
{
	  $random=substr(str_shuffle('ABCDEFGHJKLMNPQRSTUVWXYZ23456789'),0,4);
      $_SESSION[$s] = md5($random);
      return $random;
}

public function get_image($session)
{
      foreach (glob('securityimages/*.jpg') as $filename){if(filemtime($filename)<(time()-300)){@unlink($filename);}}
      $ip=$_SERVER['REMOTE_ADDR'];
      $time=time();
      $time=substr($time,-4);
      $filename='securityimages/'.str_replace('.','',$ip).$time.'.jpg';
      @unlink($filename);
      $img = @imagecreatetruecolor(50, 16)
           or die("Unable to create verification image!");
      $black = imagecolorallocate($img, 0, 0, 0);
      $white = imagecolorallocate($img, 255, 255, 255);
      imagefill($img, 0, 0, $white);
      for ($i = 0; $i < 30; $i++){
          $x = rand(0,40);
          $y = rand(0,15);
          imagesetpixel($img, $x, $y, $black);}
      imagestring($img, 5, 0, 0,  $this->verificationcode($session), $black);
      imagejpeg($img,$filename);
      imagedestroy($img);
	  echo 'http://'.str_replace($_SERVER['DOCUMENT_ROOT'], $_SERVER['HTTP_HOST'],str_replace('securityimage.php',$filename,str_replace('\\','/',__FILE__)));
      exit;
}
}
session_start();
$i=new verification;
$session=rawurldecode($_POST['session']);
$i->get_image($session);
?>
Return current item: Spam free PHP GuestBook