 |
|
Code (PHP)
<?php
session_start();
include("captchaZDR.php");
$capt = new captchaZDR;
$capt->display();
?>
Code (PHP)
<?php
session_start();
if($_SESSION['captcha']!=$_POST['capt'] || $_SESSION['captcha']=='BADCODE') {
exit("You input code is wrong");
}
?>
<?php
//Check if form submit with capt variable
if(!isset($_POST['submit']) || !isset($_POST['capt'])) {
//Form not submit return error
exit("Error");
}
//correct captcha continue program
echo "Excellent";
// ....................
?>
Code (PHP)
<?php
//Check if submit form with capt variable
if(isset($_POST['submit']) && isset($_POST['capt'])) {
//session must be start to perform check
session_start();
//check input capt with session captcha
if($_SESSION['captcha']!=$_POST['capt'] || $_SESSION['captcha']=='BADCODE')
{
//wrong captcha exit the program not continue.
exit("wrong code");
} else {
//correct captcha continue program
echo "Excellent";
// your program code here
}
} else {
//Form not submit then show input form
echo '
}
?>
Code (PHP)
<?php
class captchaZDR {
var $UserString;
var $font_path;
function captchaZDR(){
$fonts = array('Vera.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMono.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraSe.ttf', 'VeraSeBd.ttf');
shuffle($fonts);
$this->font_path = './fonts/'.current($fonts);
}
function LoadPNG(){
$bgNUM = rand(1,8);
$im = @imagecreatefrompng('./png/bg'.$bgNUM.'.png'); /* Attempt to open */
if (!$im) {
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function drawElipse($image){
for($i=0;$i<5;$i++){
// choose a color for the ellipse
$red = rand(0,155);
$green = rand(0,155);
$blue = rand(0,155);
$col_ellipse = imagecolorallocate($image, $red, $green, $blue);
// draw the ellipse
$cx = rand(50,250);
$cy = rand(50,250);
$cw = rand(30,250);
$ch = rand(20,250);
imageellipse($image, $cx, $cy, $cw, $ch, $col_ellipse);
}
foreach (range('A', 'Z') as $letter) {
$red = rand(0,155);
$green = rand(0,155);
$blue = rand(0,155);
$col_ellipse = imagecolorallocate($image, $red, $green, $blue);
$font_size = 3; //rand(1,12);
$x = rand(0,200);
$y = rand(0,100);
imagechar($image, $font_size, $x, $y, $letter, $col_ellipse);
}
foreach (range('0', '9') as $letter) {
$red = rand(0,155);
$green = rand(0,155);
$blue = rand(0,155);
$col_ellipse = imagecolorallocate($image, $red, $green, $blue);
$font_size = 1;
$x = rand(0,200);
$y = rand(0,100);
imagechar($image, $font_size, $x, $y, $letter, $col_ellipse);
}
}
function task_string(){
// create a image from png bank
$image = $this->LoadPNG();
$string_a = array("A","B","C","D","E","F","G","H","J","K",
"L","M","N","P","R","S","T","U","V","W","X","Y","Z",
"2","3","4","5","6","7","8","9");
$width=0;
for($i=0;$i<5;$i++)
{
$colour = imagecolorallocate($image, rand(0,155), rand(0,155), rand(0,155));
$font = $this->font_path;
$angle = rand(-15,15);
// Add the text
$width_pos = rand(20,30);
$width = $width + $width_pos;
// $height = rand(35,75);
$height = rand(35,46);
$temp = $string_a[rand(0,25)];
$this->UserString .= $temp;
imagettftext($image, 26, $angle, $width, $height, $colour, $font, $temp);
$width = $width + 3;
$height = $height + 3;
imagettftext($image, 26, $angle, $width, $height, $colour, $font, $temp);
}
$_SESSION['captcha'] = $this->UserString;
return $image;
}
function display(){
$image = $this->task_string();
$this->drawElipse($image);
// output the picture
header("Content-type: image/png");
imagepng($image);
}
function check_result(){
if($_SESSION['captcha']!=$_REQUEST['capt'] || $_SESSION['captcha']=='BADCODE')
{
$_SESSION['captcha']='BADCODE';
return false;
}
else
{
return true;
}
}
}
?>
นี้คือ code ทั้งหมดครับ ที่ผมมี
ทำไมมันถึงไม่แสดง รูปภาพ Code ให้เห็น เพราะตรงนี้ <img src="./captcha/captcha_img.php"> หรือป่าวครับ
ขอคำแนะนำหน่อยครับ
|
 |
 |
 |
 |
Date :
2011-06-29 12:48:01 |
By :
เด็กฝึกหัด |
|
 |
 |
 |
 |
|
|
 |