站点移动后,Captcha断了

时间:2012-05-08 17:12:05

标签: php captcha

我最近为我的网站移动了服务器。然而验证码功能(从captcha.php拉入是不工作。我检查权限,这一切似乎都很好,还有什么可能会出错? The site

Captcha表格朝向底部。我觉得它很简单,我想念它!

Captcha.php:

<?php
//Start the session so we can store what the security code actually is
session_start();

//Send a generated image to the browser 
create_image(); 
exit(); 

function create_image() 
{ 

    // Set the content-type
    header("Content-type: image/jpg");

    // Create the image
    $im = imagecreatetruecolor(100, 30);

    // Create some colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 128, 128, 128);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 399, 29, $white);

    // The text to draw
    $text =  $_SESSION["captcha"];
    // Replace path by your own font path
    $font = 'caviardreams.ttf';

    // Add some shadow to the text
    imagettftext($im, 15, 0, 11, 21, $grey, $font, $text);

    // Add the text
    imagettftext($im, 15, 0, 10, 20, $black, $font, $text);

    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($im);
    imagedestroy($im);
} 

?>

这是修复(添加$ font = realpath($ font);):

<?php
//Start the session so we can store what the security code actually is
session_start();

//Send a generated image to the browser 
create_image(); 
exit(); 

function create_image() 
{ 

    // Set the content-type
    header("Content-type: image/jpg");

    // Create the image
    $im = imagecreatetruecolor(100, 30);

    // Create some colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 128, 128, 128);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 399, 29, $white);

    // The text to draw
    $text =  $_SESSION["captcha"];
    // Replace path by your own font path
    $font = 'caviardreams.ttf';
    $font = realpath($font);

    // Add some shadow to the text
    imagettftext($im, 15, 0, 11, 21, $grey, $font, $text);

    // Add the text
    imagettftext($im, 15, 0, 10, 20, $black, $font, $text);

    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($im);
    imagedestroy($im);
} 

?>

1 个答案:

答案 0 :(得分:1)

我想它需要PHP才能拥有GD installed,但是如果不知道服务器在尝试渲染验证码时遇到的错误,则无法判断。检查你的日志。