Witam!
Były podobne wątki ale żadna z recept nie działa:
Problem wygląda tak :
obrazek z kodem jest generowany przez skrypt PHP, używając bibliotek GD.
Na jednym serwerze identyczny skrypt działa , na drugim nie,
plik z czcionką jest w katalogu głównym zapisany małymi literami,
Na obu serwerach jest ta sama wersja PHP 5.2.17,
Są zainstalowane biblioteki GD
phpinfo() daje różne wyniki :
na serwerze na którym nie działa w tabeli GD brakuje linijek:
"
FreeType Linkage with freetype
FreeType Version 2.3.7
T1Lib Support enabled
"
Mają one jak sądzę wpływ na akceptowanie adresowania, ale z adresem do czcionki względnym , bezwzględnym, z ./ i bez, z realpath i bez nie działa;
Błąd jest zawsze ten sam obrazek nie może zostać wyświetlony, ponieważ zawiera błędy.
Na tym też serwerze był podobny problem z czcionką o adresie :
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold" type="text/css" />
Kod captcha.php:
header('Content-Type: image/jpeg');
ini_set('default_charset', 'UTF-8'); /* Config variables */
$width = 112;
$height = 24;
$characters = 6;
/* Create random string */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
for ($i = 0; $i < $characters; $i++) $code .= substr($possible, mt_rand(0
, strlen($possible)-1
), 1
);
/* Create image */
$font_size = $height * 0.65;
$image = imagecreatetruecolor
($width, $height) or
die('Error: Cannot create image using GD'); $background_colour = imagecolorallocate($image, 10, 40, 20);
$text_colour = imagecolorallocate($image, 130, 150,180);
$noise_colour = imagecolorallocate($image, 60, 120, 80);
for( $i=0; $i<($width*$height)/3; $i++ ) imagefilledellipse
($image, mt_rand(0
,$width), mt_rand(0
,$height), 1
, 1
, $noise_colour); for( $i=0; $i<($width*$height)/150; $i++ ) imageline
($image, mt_rand(0
,$width), mt_rand(0
,$height), mt_rand(0
,$width), mt_rand(0
,$height), $noise_colour); $textbox = imagettfbbox
($font_size, 0
, $font, $code) or
die('Error: imagettfbbox function failure'); $x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext
($image, $font_size, 0
, $x, $y, $text_colour, $font , $code) or
die('Error: imagettftext function failure');
/* Save code in session */
$_SESSION['security_code'] = $code;
/* Output image */
imagejpeg($image);
imagedestroy($image);
proszę o sugestie