0

キャプチャ単語画像を作成しようとしていますが、画像が表示されません。これは私がこれまでに持っているものです:

<?php  

session_start();  

$string = '';  

for ($i = 0; $i < 5; $i++) {  
    $string .= chr(rand(97, 122));  
}  

$_SESSION['random_code'] = $string; 

$dir = 'fonts/';  

$image = imagecreatetruecolor(170, 60);  
$black = imagecolorallocate($image, 0, 0, 0);  
$color = imagecolorallocate($image, 200, 100, 90); // red  
$white = imagecolorallocate($image, 255, 255, 255); 

imagefilledrectangle($image,0,0,200,100,$white);  
imagettftext($image, 30, 0, 10, 40, $alt, $dir."arial.ttf", $_SESSION['rand_code']);
header("Content-type: image/png");  
imagepng($image);  

?> 

なぜこれが機能しないのかわかりません。どんな助けでも大歓迎です。

4

1 に答える 1

0

なぜ独自のキャプチャが必要なのですか? ReCaptcha ですよね?
Ok..

// generate random number and store in session

$randomnum = rand(1000, 9999);
$_SESSION['randomnum'] = md5($randomnum);

//generate image
$im = imagecreatetruecolor(100, 38);

//colors:
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 200, 35, $black);

//path to font:

$font = 'fonts/font.ttf';

//draw text:
imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnum);

imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnum);

// prevent client side  caching
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//send image to browser
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);

そしてフォーム

<form method="post" action="write.php">
    <input class="input" type="text" name="norobot" />
    <img src="captcha.php" />
    <input type="submit" value="Submit" />
</form>

そして write.php

session_start();
if (md5($_POST['norobot']) == $_SESSION['randomnum2'])  { 
    // here you  place code to be executed if the captcha test passes
        echo "Hey great , it appears you are not a robot";
}   else {  
    // here you  place code to be executed if the captcha test fails
        echo "you're a very naughty robot!";
}
于 2013-06-22T05:18:04.450 に答える