.fatemeh
شنبه 21 خرداد 1390, 09:57 صبح
سلام دوستان
من یه کد آماده برای این تصاویر را از همین سایت دانلود کردم ولی تصویر امنیتی نمایش داده نمیشه.
تابع php_gd2.dll هم در php .ini فعال کردم.
می شه راهنمایی کنید باید چه کار کنم.
صفحه test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form example</title>
<body>
<p align="center">test of Captcha </p>
<form id="form1" name="form1" method="post" action="page2.php">
<label></label>
<label> <br />
<input name="cap" dir="rtl" type="text" id="cap" value=""/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<div id="captcha">
<p><img src="image.php" id="im_sec" /> </p>
</div>
<p><a href="#" onclick="document.getElementById('im_sec').src='image.php?R eload_id=' + Math.random(); return false">ریست تصویر </a></p>
</body>
</html>
صفحه image.php
<?
require_once("Image_sec.php");
$aa= new Image_securety();
$aa->Show_Image();
?>
صفحه Image_sec.php
class Image_Securety {
var $width=180; // width of image
var $height=50; // height of image
// english font file you can change it
var $En_ttf_file="MINYN___.ttf";
//index ttf file (english or persian)
var $ttf;
// output format (png,jpeg,gif,bmp)
var $format="png";
var $font_size = "30";
// lenght of string(captcha) for show on image
var $str_lenght = "5";
//the X t position On image where letter drawing will begin
var $Text_x=30;
//the Y t position On image where letter drawing will begin
var $Text_y=30;
// The background color for the image
//var $Back_Color = array(0,0,200);
// set to true draw line on image
var $draw_Lines=true;
// add noise
var $Noise=true;
var $NoiseCount=400;
var $Lines_Color=array(100,100,0);
var $Text_Color = array(100, 255, 0);
// set to true draw twisty lin on image
var $Draw_Twisty_line=false;
var $T_Line_Color= array(236,50,0);
var $angle_Rotation=array(-5,25);
//How thick to draw the twisty lines
var $thick=3;
var $code;
var $img;
var $error;
/*******************************************/
// set up image
function Image_Create(){
//creat image
$this->img=imagecreate( $this->width, $this->height );
// image back color
for ($i=1; $i<=200; $i++)
{
$r = round( rand( 0, 180 ) );
$g = round( rand( 0, 100 ) );
$b = round( rand( 0, 200 ) );
$BG = imagecolorallocate($this->img,$r,$g,$b);
imagefilledellipse( $this->img,round(rand(0,$this->width)), round(rand(0,$this->height)), round(rand(0,$this->width/12)), round(rand(0,$this->height/2)), $BG );
} // end of for
}
/************************************************** *********/
// draw lines on image
function d_lines()
{
if(draw_Lines)
{
// color of lines
$linecolor = imagecolorallocate($this->img,$this->Lines_Color[0],$this->Lines_Color[1],$this->Lines_Color[2]);
//horizontal lines
for($x=5; $x<=$this->height; $x+=7)
imageline($this->img,0,$x,$this->width,$x,$linecolor);
// vertical lines
for($y=3; $y<=$this->width; $y+=10)
imageline($this->img,$y,0,$y,$this->height,$linecolor);
}
}
/************************************************** ************/
// add noise on image
function AddNoise(){
if($this->Noise){
$noise_color = imagecolorallocate($this->img, 255, 255, 255);
for( $i=0; $i<$this->NoiseCount; $i++ ) {
imagefilledellipse($this->img, mt_rand(0,$this->width), mt_rand(0,$this->height), 1, 1, $noise_color);
}
}
}
/************************************************** ***********/
// draw twisty line on image
function T_line()
{
if($this->Draw_Twisty_line){
$T_color =imagecolorallocate($this->img,$this->T_Line_Color[0],$this->T_Line_Color[1],$this->T_Line_Color[2]);
imagesetthickness($this->img,$this->thick);
$x_start=rand(3,25);
$y_start=rand(3,10);
$x_end=rand(30,$this->width);
$y_end=rand(13,$this->height);
imageline($this->img,$x_start,$y_start,$x_end,$y_end,$T_color);
}
}
/************************************************** ************/
// draw word on image
function Write_On_Img()
{
Image_Securety::Image_Create();
Image_Securety::d_lines();
Image_Securety::AddNoise();
Image_Securety::Random_str($this->str_lenght);
$text_color = imagecolorallocate($this->img,$this->Text_Color[0],$this->Text_Color[1],$this->Text_Color[2]);
$angle=rand($this->angle_Rotation[0],$this->angle_Rotation[2]);
// wirte words on image
imagettftext($this->img,$this->font_size,$angle,$this->Text_x,$this->Text_y,$text_color,$this->ttf,$this->code);
}
/************************************************** *******************/
// output image
function Show_Image()
{
Image_Securety::Write_On_Img();
Image_Securety::T_line();
Image_Securety::Make_session();
// output type
switch(strtolower($this->format)){
case "png" :
header("Content-type: image/png");
imagepng($this->img);
break;
case "gif" :
header("Content-type: image/gif");
imagegif($this->img);
break;
case "jpeg" :
header("Content-type: image/jpeg");
imagejpeg($this->img);
break;
case "bmp" :
header("Content-type: image/bmp");
imagewbmp($this->img);
break;
}
// clean up
imagedestroy($this->img);
}//end of write_on_img
/************************************************** ************/
// Function To Create Random String
function random_str($length )
{
$randstr = '';
srand((double)microtime()*1000000);
$chars = array ('a','b','c','d','e','f','g','j','h','i','k','l',' m','n','o','q','p','r','s','t','u','v','x','y','z' ,'A','B','C','D','E','F','G','J','H','I','K','L',' M','N','Q','P','R','S','T','U','V','X','Y','Z','1' ,'2','3','4','5','6','7','8','9');
$totalchars = count($chars);
for ($i = 0; $i < $length; $i++)
{
$random = rand(0, $totalchars - 1);
$randstr .= $chars[$random];
}
$this->code=$randstr;
$this->ttf = $this->En_ttf_file;
}
/************************************************** ***************/
// create session for save data
function Make_session()
{
session_start();
$_SESSION['captcha']=strtolower(trim($this->code));
}
/******************************************/
} // end of class
/*******************/
?>
صفحه page2
<title>Result</title>
<?php
if(isset($_POST['Submit'])){
session_start();
if($_POST['cap']==$_SESSION['captcha']){
echo "WELCOME TO MY WEB";}
else
echo "Invalid Your code";
}
?>
من یه کد آماده برای این تصاویر را از همین سایت دانلود کردم ولی تصویر امنیتی نمایش داده نمیشه.
تابع php_gd2.dll هم در php .ini فعال کردم.
می شه راهنمایی کنید باید چه کار کنم.
صفحه test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form example</title>
<body>
<p align="center">test of Captcha </p>
<form id="form1" name="form1" method="post" action="page2.php">
<label></label>
<label> <br />
<input name="cap" dir="rtl" type="text" id="cap" value=""/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<div id="captcha">
<p><img src="image.php" id="im_sec" /> </p>
</div>
<p><a href="#" onclick="document.getElementById('im_sec').src='image.php?R eload_id=' + Math.random(); return false">ریست تصویر </a></p>
</body>
</html>
صفحه image.php
<?
require_once("Image_sec.php");
$aa= new Image_securety();
$aa->Show_Image();
?>
صفحه Image_sec.php
class Image_Securety {
var $width=180; // width of image
var $height=50; // height of image
// english font file you can change it
var $En_ttf_file="MINYN___.ttf";
//index ttf file (english or persian)
var $ttf;
// output format (png,jpeg,gif,bmp)
var $format="png";
var $font_size = "30";
// lenght of string(captcha) for show on image
var $str_lenght = "5";
//the X t position On image where letter drawing will begin
var $Text_x=30;
//the Y t position On image where letter drawing will begin
var $Text_y=30;
// The background color for the image
//var $Back_Color = array(0,0,200);
// set to true draw line on image
var $draw_Lines=true;
// add noise
var $Noise=true;
var $NoiseCount=400;
var $Lines_Color=array(100,100,0);
var $Text_Color = array(100, 255, 0);
// set to true draw twisty lin on image
var $Draw_Twisty_line=false;
var $T_Line_Color= array(236,50,0);
var $angle_Rotation=array(-5,25);
//How thick to draw the twisty lines
var $thick=3;
var $code;
var $img;
var $error;
/*******************************************/
// set up image
function Image_Create(){
//creat image
$this->img=imagecreate( $this->width, $this->height );
// image back color
for ($i=1; $i<=200; $i++)
{
$r = round( rand( 0, 180 ) );
$g = round( rand( 0, 100 ) );
$b = round( rand( 0, 200 ) );
$BG = imagecolorallocate($this->img,$r,$g,$b);
imagefilledellipse( $this->img,round(rand(0,$this->width)), round(rand(0,$this->height)), round(rand(0,$this->width/12)), round(rand(0,$this->height/2)), $BG );
} // end of for
}
/************************************************** *********/
// draw lines on image
function d_lines()
{
if(draw_Lines)
{
// color of lines
$linecolor = imagecolorallocate($this->img,$this->Lines_Color[0],$this->Lines_Color[1],$this->Lines_Color[2]);
//horizontal lines
for($x=5; $x<=$this->height; $x+=7)
imageline($this->img,0,$x,$this->width,$x,$linecolor);
// vertical lines
for($y=3; $y<=$this->width; $y+=10)
imageline($this->img,$y,0,$y,$this->height,$linecolor);
}
}
/************************************************** ************/
// add noise on image
function AddNoise(){
if($this->Noise){
$noise_color = imagecolorallocate($this->img, 255, 255, 255);
for( $i=0; $i<$this->NoiseCount; $i++ ) {
imagefilledellipse($this->img, mt_rand(0,$this->width), mt_rand(0,$this->height), 1, 1, $noise_color);
}
}
}
/************************************************** ***********/
// draw twisty line on image
function T_line()
{
if($this->Draw_Twisty_line){
$T_color =imagecolorallocate($this->img,$this->T_Line_Color[0],$this->T_Line_Color[1],$this->T_Line_Color[2]);
imagesetthickness($this->img,$this->thick);
$x_start=rand(3,25);
$y_start=rand(3,10);
$x_end=rand(30,$this->width);
$y_end=rand(13,$this->height);
imageline($this->img,$x_start,$y_start,$x_end,$y_end,$T_color);
}
}
/************************************************** ************/
// draw word on image
function Write_On_Img()
{
Image_Securety::Image_Create();
Image_Securety::d_lines();
Image_Securety::AddNoise();
Image_Securety::Random_str($this->str_lenght);
$text_color = imagecolorallocate($this->img,$this->Text_Color[0],$this->Text_Color[1],$this->Text_Color[2]);
$angle=rand($this->angle_Rotation[0],$this->angle_Rotation[2]);
// wirte words on image
imagettftext($this->img,$this->font_size,$angle,$this->Text_x,$this->Text_y,$text_color,$this->ttf,$this->code);
}
/************************************************** *******************/
// output image
function Show_Image()
{
Image_Securety::Write_On_Img();
Image_Securety::T_line();
Image_Securety::Make_session();
// output type
switch(strtolower($this->format)){
case "png" :
header("Content-type: image/png");
imagepng($this->img);
break;
case "gif" :
header("Content-type: image/gif");
imagegif($this->img);
break;
case "jpeg" :
header("Content-type: image/jpeg");
imagejpeg($this->img);
break;
case "bmp" :
header("Content-type: image/bmp");
imagewbmp($this->img);
break;
}
// clean up
imagedestroy($this->img);
}//end of write_on_img
/************************************************** ************/
// Function To Create Random String
function random_str($length )
{
$randstr = '';
srand((double)microtime()*1000000);
$chars = array ('a','b','c','d','e','f','g','j','h','i','k','l',' m','n','o','q','p','r','s','t','u','v','x','y','z' ,'A','B','C','D','E','F','G','J','H','I','K','L',' M','N','Q','P','R','S','T','U','V','X','Y','Z','1' ,'2','3','4','5','6','7','8','9');
$totalchars = count($chars);
for ($i = 0; $i < $length; $i++)
{
$random = rand(0, $totalchars - 1);
$randstr .= $chars[$random];
}
$this->code=$randstr;
$this->ttf = $this->En_ttf_file;
}
/************************************************** ***************/
// create session for save data
function Make_session()
{
session_start();
$_SESSION['captcha']=strtolower(trim($this->code));
}
/******************************************/
} // end of class
/*******************/
?>
صفحه page2
<title>Result</title>
<?php
if(isset($_POST['Submit'])){
session_start();
if($_POST['cap']==$_SESSION['captcha']){
echo "WELCOME TO MY WEB";}
else
echo "Invalid Your code";
}
?>