@meucoz

Не выводит капчу, почему?

Не выводит капчу на сайте: понятия не имею почему. На денвере все работает идеально.

Вывод капчи:
<fieldset id="usercaptcha_fieldset" class="control-group">
                            <label for="user_captcha" class="control-label"><?php echo $TEXT['captcha']; ?>:</label>
                            <div class="controls">
                                <span style="display: block;">
                                <input id="user_captcha" tabindex="4" maxlength="3" style="width: 100px;float:left;" name="user_captcha" type="text" value="">
                                <span class="captcha"><img alt="captcha" src="/captcha/captcha2.php"></span>
                                </span>
                                <p style="clear: both"><?php echo $TEXT['captcha-comment']; ?></p>
                            </div>
                        </fieldset>


Код файла captcha2.php:

<?php
session_start();

$letras = '0123456789';

$ancho_caja = 60;
$alto_caja = 36;
$tam_letra = 10;
$tam_letra_grande = 24;

$angmax = 15;

header("Content-type: image/png");

$im = imagecreate($ancho_caja, $alto_caja);

$gris = ImageColorAllocate($im, 255, 255, 255);
$colorLetra = ImageColorAllocate($im, 0, 0, 0);
$colorLetraFondo = ImageColorAllocate($im, 253, 253, 253);

$fuente = 'captcha.ttf';

$caja_texto = imagettfbbox($tam_letra, 0, $fuente , $letras);
$alto_linea = abs($caja_texto[7]-$caja_texto[1]);
$num_lineas = intval($alto_caja / $alto_linea)+1;

$pos = 0;
for ($i = 0; $i<$num_lineas; $i++) {
    $x = 0;
    for ($j = 0; $j<30; $j++) {
        $texto_linea = $letras[rand(0, strlen($letras)-1)].' ';
        $caja_texto = imagettfbbox($tam_letra, 0, $fuente , $texto_linea);
    	imagettftext($im, $tam_letra, rand(-$angmax, $angmax), $x, $alto_linea*$i, $colorLetraFondo, $fuente , $texto_linea);
        // Posicion x de la siguiente letra
        $x += $caja_texto[2] - $caja_texto[0];
    }
}

$res = $letras[rand(0, strlen($letras)-1)];
$ang1 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang1, $fuente , $res);
$y1 = abs($caja_texto[7]-$caja_texto[1]);
$x1 = abs($caja_texto[2]-$caja_texto[0]);

$res .= $letras[rand(0, strlen($letras)-1)];
$ang2 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang2, $fuente , $res[1]);
$y2 = abs($caja_texto[7]-$caja_texto[1]);
$x2 = abs($caja_texto[2]-$caja_texto[0]);

$res .= $letras[rand(0, strlen($letras)-1)];
$ang3 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang3, $fuente , $res[2]);
$y3 = abs($caja_texto[7]-$caja_texto[1]);
$x3 = abs($caja_texto[2]-$caja_texto[0]);

imagettftext($im, $tam_letra_grande, $ang1, ($ancho_caja/2)-(($x1+$x2+$x3)/2), $y1+($alto_caja-$y1)/2, $colorLetra, $fuente , $res[0]);
imagettftext($im, $tam_letra_grande, $ang2, ($ancho_caja/2)-(($x1+$x2+$x3)/2)+($x1), $y2+($alto_caja-$y2)/2, $colorLetra, $fuente , $res[1]);
imagettftext($im, $tam_letra_grande, $ang3, ($ancho_caja/2)-(($x1+$x2+$x3)/2)+($x1+$x2), $y3+($alto_caja-$y3)/2, $colorLetra, $fuente , $res[2]);

imagepng($im);
imagedestroy($im);
imagedestroy($im2);

$_SESSION["captcha"] = $res;
?>


В FileZilla права "777" на папку "captcha"
  • Вопрос задан
  • 372 просмотра
Пригласить эксперта
Ответы на вопрос 1
webinar
@webinar Куратор тега PHP
Учим yii: https://youtu.be/-WRMlGHLgRg
1. Проверьте установлен ли GD и включен ли
<?php echo phpinfo(); ?>
2. Проверьте работают ли сессии
<?php
if(isset($_SESSION['captcha']))
{
echo "с сессией все норм видимо, насяльника";
}
?>

3. Классика: включите вывод всех ошибок на сервере
<?php
  ini_set("display_errors", "1");
  error_reporting(E_ALL); 
  ?>
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы