我最近为我的网站移动了服务器。然而验证码功能(从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);
}
?>