PHP 인증 코드 검사 기능 구현
맨 위 에 함수 sessionstart(); 서버 에 우리 가 이 함수 의 기능 을 사용 해 야 한다 고 알려 주세요.
session_start();
다음 에 우리 가 사용 하 는 것 은 바로 인증 코드 가 실 현 된 코드 이다.여기에 영문 숫자의 코드 를 예 로 들 자.
$image = imagecreatetruecolor(100, 30); // 100×30
$white = imagecolorallocate($image,255,255,255);//
imagefill($image,0,0,$white);//
그리고 인증 코드 가 실현 되 기 전에 빈 변 수 를 설명 하여 인증 코드 를 저장 합 니 다.
$session = ""; // ,
for($i=0;$i<4;$i++){
$size = 6;
$x = $i*25+mt_rand(5,10);
$y = mt_rand(5,10);
$sizi_color = imagecolorallocate($image,mt_rand(80,220),mt_rand(80,220),mt_rand(80,220));
$char = join("",array_merge(range('a','z'),range('A','Z'),range(0,9)));
$char = str_shuffle($char);
$char = substr($char,0,1);
imagestring($image,$size,$x,$y,$char,$sizi_color);
$session .= $char ; //
}
$_SESSION['session'] = $session; //
for($k=0;$k<200;$k++){
$rand_color = imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imagesetpixel($image,mt_rand(1,99),mt_rand(1,29),$rand_color);
}
for($n=0;$n<5;$n++){
$line_color = imagecolorallocate($image,mt_rand(80,220),mt_rand(80,220),mt_rand(80,220));
imageline($image,mt_rand(1,99),mt_rand(1,29),mt_rand(1,99),mt_rand(1,29),$line_color);
}
header('content-type:image/png');//
imagepng( $image ); // png $image
imagedestroy( $image ); //
POST 방식 으로 인증 코드 를 받다.strtolower 함 수 는 서버 가 대소 문 자 를 구분 하지 않도록 하 는 것 입 니 다.이렇게 하면 사용자 의 실수 율 을 효과적으로 줄 일 수 있다.
if(isset($_POST['session'])){
session_start();
if(strtolower($_POST['session'])==strtolower($_SESSION['session'])){
echo'<font color="#0000CC"> </form>';
}else{
echo '<font color="#CC0000"><b> </b></font>';
}
exit();
}
다음은 HTML 페이지 코드 입 니 다.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title> </title>
</head>
<body>
<form method="post" action="./tushu.php">
<p> :<img id="img" border="1" src="http://localhost//xxx.php" width="100" height="30"></p>
<a href="javascript:void(0)" rel="external nofollow" onclick="document.getElementById('img').src='http://localhost//xxx.php'"> ? </a>
<p> :<input type="text" name="session" value=""/></p>
<p><input type="submit" value=" " style="padding:6px 10px;"></p>
</form>
</body>
</html>
HTML 코드 에 이벤트 onclick 이 추가 되 었 습 니 다.사용자 가 현재 인증 코드 를 식별 할 수 없 을 때 브 라 우 저 를 새로 고치 지 않 고'잘 보이 지 않 습 니까?'"하 나 를 바 꾸 면 인증 코드 를 바 꿀 수 있 습 니 다."이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
laravel에 yo에서 angularJs&coffeescript를 사용할 수 있도록 한다.먼저 yo 명령을 사용할 수 있어야하므로 아래에서 설치 global에 설치한 곳에서 laravel의 프로젝트 루트로 이동. 클라이언트 코드를 관리하는 디렉토리를 만들고 이동합니다. 클라이언트 환경 만들기 이것으로 히...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.