-1

我最近为我的网站移动了服务器。但是,验证码功能(从 captcha.php 中提取的功能不起作用。我检查了权限,一切似乎都很好,还有什么问题? 该网站

验证码表格朝向底部。我有一种感觉,我想念一些简单的东西!

验证码.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);
} 

?>
4

1 回答 1

1

我想它需要 PHP 来安装GD,但是如果不知道您的服务器在尝试呈现验证码时遇到的错误,就无法判断。检查您的日志。

于 2012-05-08T17:14:11.963 回答