GD2 기능을 사용하여 4자리 인증 코드를 생성할 때 사진이 표시되지 않는 이유는 무엇입니까?
S.L
S.L 2017-08-21 20:38:54
0
1
1221

<?php
session_start();
header("content-type:image/png") //생성된 이미지의 형식을 설정합니다
$image_width=70; 이미지 너비
$image_height=18; //이미지 높이 설정
srand(microtime()*100000) //난수의 시드 설정
for($i=0;$i<4;$i++); //4자리 난수를 출력하는 루프
$new_number.=dechex(rand(0,15));
}
$_SESSION[check_checks]=$new_number; //얻은 난수 인증코드를 SESSION 변수에 씁니다.

$num_image =imagecreate($image_width,$image_height); //캔버스 만들기
imagecolorallocate($num_image,255,255,255) //캔버스 색상 설정
for($i=0;$i<strlen($ _SESSION[check_checks]); $i++){ //SESSION 변수에서 확인 코드를 읽는 루프
$font=mt_rand(3,5) ); //색상 설정 문자 수
imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color); //가로 문자 출력
}
imagepng ($num_image);

S.L
S.L

모든 응답(1)
风豆丁

코드에 오류가 많습니다.

header("content-type:image/png")를 먼저 주석 처리하고 오류를 먼저 처리하세요.

일반적으로 헤더는 이미지를 생성하는 imagepng() 함수 위에 설정되므로 오류를 쉽게 조정할 수 있습니다.

  • 회신하다 이 코드는 튜토리얼에서 복사되었으므로 정확해야 합니다. 귀하의 방법에 따라 작동하지 않으며 다음 오류가 발생합니다. ( ! ) 주의 사항: 정의되지 않은 변수: 7행의 D:wamp64wwwlianxichecks.php에 있는 new_number 호출 스택 # 시간 기억 기능 위치 1 0.0007 244832 {메인}( ) ...checks.php:0
    S.L 작가 2017-08-22 23:22:07
  • 회신하다 for 루프 앞에 $num_number에 초기 값을 지정하고 $_SESSION 아래 첨자는 문자열이어야 합니다. 다음과 같이 변경하면 됩니다. 세션_시작(); header("content-type:image/png"); //생성된 이미지의 형식을 설정합니다. $image_width=70; //이미지 너비 설정 $image_height=18; //이미지 높이 설정 srand(microtime()*100000); //난수 시드 설정 $new_number = ''; for($i=0;$i<4;$i++){ //4자리 난수를 출력하는 루프 $new_number .= dechex(rand(0,15)); } $_SESSION['check_checks']=$new_number; //획득한 난수 인증코드를 SESSION 변수에 씁니다. $num_image=imagecreate($image_width,$image_height); //캔버스 생성 imagecolorallocate($num_image,255,255,255); //캔버스 색상 설정 for($i=0;$i<strlen($_SESSION['check_checks']);$i++){ //SESSION 변수의 확인 코드를 읽는 루프 $font=mt_rand(3,5); //임의의 글꼴 설정 $x=mt_rand(1,8)+$image_width*$i/4; //임의의 문자 위치의 X 좌표를 설정합니다. $y=mt_rand(1,$image_height/4); //임의의 문자 위치의 Y 좌표를 설정합니다. $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)) //문자 색상을 설정합니다. imagestring($num_image,$font,$x,$y,$_SESSION['check_checks'][$i],$color) //가로 출력 문자 } imagepng($num_image); //PNG 형식으로 이미지를 생성합니다. imagedestroy($num_image); //이미지 리소스 해제
    风豆丁 작가 2017-08-23 22:23:48
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!