我的在我的OVH服务器上不工作。
当地的沃普一切都很好。在un上传之后,captcha就不会显示在我的网站上了。
我不知道我做错了什么。
我的captcha.php包括在我的表单中,如:<img src="captcha.php" alt="CAPTCHA" class="captcha-image">
PS :php已经安装并更新了。PHP版本: 7.0.33
captcha.php:
session_start();
$permitted_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
function generate_string($input, $strength = 10) {
$input_length = strlen($input);
$random_string = '';
for($i = 0; $i < $strength; $i++) {
$random_character = $input[mt_rand(0, $input_length - 1)];
$random_string .= $random_character;
}
return $random_string;
}
$image = imagecreatetruecolor(200, 50);
imageantialias($image, true);
$colors = [];
$red = rand(125, 175);
$green = rand(125, 175);
$blue = rand(125, 175);
for($i = 0; $i < 5; $i++) {
$colors[] = imagecolorallocate($image, $red - 20*$i, $green - 20*$i, $blue - 20*$i);
}
imagefill($image, 0, 0, $colors[0]);
for($i = 0; $i < 10; $i++) {
imagesetthickness($image, rand(2, 10));
$line_color = $colors[rand(1, 4)];
imagerectangle($image, rand(-10, 190), rand(-10, 10), rand(-10, 190), rand(40, 60), $line_color);
}
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$textcolors = [$black, $white];
$fonts = [dirname(__FILE__).'\fonts\Acme.ttf', dirname(__FILE__).'\fonts\Ubuntu.ttf', dirname(__FILE__).'\fonts\Merriweather.ttf', dirname(__FILE__).'\fonts\PlayfairDisplay.ttf'];
$string_length = 6;
$captcha_string = generate_string($permitted_chars, $string_length);
$_SESSION['captcha_text'] = $captcha_string;
for($i = 0; $i < $string_length; $i++) {
$letter_space = 170/$string_length;
$initial = 15;
imagettftext($image, 24, rand(-15, 15), $initial + $i*$letter_space, rand(25, 45), $textcolors[rand(0, 1)], $fonts[array_rand($fonts)], $captcha_string[$i]);
}
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
本地:https://i.imgur.com/rqTK2X3.png远程:https://i.imgur.com/Z4lEa9r.png
发布于 2019-02-10 11:05:32
好了,明白了。captcha只在PHP7.2上工作。默认情况下,Wamp有7.2,debian 9有7.0。
我刚刚安装了7.2,一切都很好。我的路径问题是用/而不是\(.)解决的。
谢谢你们所有人。
发布于 2019-02-09 10:36:58
我认为您错过了OVH服务器上的GD扩展。检查日志以确认。您的服务器向浏览器发送错误,但是由于浏览器希望看到图像,所以它会显示丢失/损坏的图像图标。
您可以使用以下命令之一安装GD (取决于PHP版本)
sudo apt-get install php7.0-gd
# or
sudo apt-get install php7.1-gd
# or
sudo apt-get install php7.2-gd
有关如何安装GD的更多详细信息,请查看install php70-gd on ubuntu
https://stackoverflow.com/questions/54609044
复制