2017-01-13 1 views
1

dictionary.txt라는 파일에서 단어를 가져 와서 GD 라이브러리를 사용하여 captcha 이미지로 변환하는 보안 문자를 만들려고합니다. 그러나 뭔가 잘못되었습니다. 사전 변수를 세션 변수로 표시 할 수는 있지만 이미지를 만들지는 못합니다. GD 라이브러리 코드 여야합니다. captcha_validate.php라는 최종 타겟 파일이 있지만, 지금은 중요하지 않습니다. 나는 단지 이미지가 작동하도록 노력하고있다. 폰트 경로가 설정되면 바로 form_captcha.php보안 문자가 php에 나타나지 않습니다

<form class="" action="captcha_validate.php" method="post"> 
    Captcha Verify: 
    <input type="text" name="captcha" value="" /><br /><br /> 
    <img src="captcha.php" /><br /> 
    <input type="submit" name="submit" value="Submit" /> 
</form> 

captcha.php

<?php 

    session_start(); 

    session_regenerate_id(); 

    $file = file('dictionary.txt', FILE_IGNORE_NEW_LINES); 

    $length = count($file) - 1; 
    $random = rand(0, $length); 

    $_SESSION['captcha'] = $file[$random]; 
    session_write_close(); 

    function msg($msg) { 
     $container = imagecreate(250, 170); 
     $black = imagecolorallocate($container, 0, 0, 0); 
     $white = imagecolorallocate($container, 255, 255, 255); 
     $font = "C:\Windows\Fonts\arial.ttf"; 
     imagefilledrectangle($container, 0, 0, 250, 170, $black); 

     $px = (imagesx($container)/(strlen($msg)/1.15)); 
     $py = (imagesy($container)/3.5); 

     imagefttext($container, 28, -27, $px, $py, $white, $font, $msg); 
     header("Content-type: image/png"); 
     imagepng($container, null); 
     imagedestroy($container); 
    } 

    msg($file[$random]); 

    ?> 
+0

'Imagepng' man 페이지에'quality와 filters 인수가 사용되지 않으면 NULL이 유효하지 않습니다. ' –

+0

나는 이것을했고 여전히 효과가 없다. imagepng ($ 컨테이너, null, 0, PNG_NO_FILTER); –

답변

0

시도는 테스트. 필자는 테스트 유트트 스크립트를 사용했는데, 제 환경에 적합한 글꼴 경로를 설정할 때 작동했습니다.

같은 :

$ 글꼴 = './SomeFont.ttf';

+0

나는 왜 저를 위해 작동하지 않는 얻지 않는다. –

+0

좋아, 그래서 내 captcha 파일에 html을 사용하고 있었고 나는 그 경우에 그것을 사용하지 않아야했다. –

0

좋아요, 그래서 captcha.php 파일에서 html을 사용하고있는 것으로 밝혀졌습니다. 그것이 내 코드가 작동하지 않는 주된 이유입니다. 시도해 주셔서 감사합니다.

관련 문제