PHP 인증 코드 클래스 및 호출 예시 공유
本文分享一个不错的php 验证码类,后面附有完整的调用示例,有需要的朋友,参考下吧。
1,php验证码类 <?php // usage: /* 显示验证码: <img src="/static/imghw/default1.png" data-src="captcha.php?cap=login.png" class="lazy" alt="PHP 인증 코드 클래스 및 호출 예시 공유" > 检查验证码: 检查输入的验证码与 $_SESSION['login'] 中保存的值是否相等。 */ error_reporting(E_ALL); session_start(); (!isset($_GET['cap']))?die('Error !'):1; $captcha_array=array('login.png','contact.png','comment.png'); (!in_array($_GET['cap'],$captcha_array))?die('Error !'):1; $captcha_cod=new captcha(basename($_GET['cap'],'.png')) ; //验证码类 class captcha { private $session_name; private $image_width; private $image_height; private $cod_length; private $cod_mode; private $font_path; private $avtage_font_size; private $sec_cod; private $res_image; function __construct($name,$width=200,$height=50,$length=5,$mod=2,$font='arial.ttf',$av_font_size=25) { $this-> session_name = $name ; $this-> image_width = $width ; $this-> image_height = $height ; $this-> cod_length = $length ; $this-> mode = $mod ; $this-> font_path = $font ; $this-> avrage_font_size = $av_font_size ; $this->Gen_Cod(); } function Write_Text($text) { $x_pos=10; for($pos=0;$pos<strlen($text);$pos++) { imagettftext($this->res_image,rand($this->avrage_font_size -2,$this->avrage_font_size +2), rand(-40,+40),$x_pos,rand(35,$this->image_height - $this->avrage_font_size), imagecolorallocate($this->res_image,rand(0,150),rand(0,150),rand(0,150)), $this->font_path,$text[$pos]); $x_pos+=($this->image_width/$this->cod_length); } } function Draw_Line() { // for($pos=0;$pos<$this->image_height;$pos+=8) imageline($this->res_image,0,$pos,$this->image_width,$pos,imagecolorallocate($this->res_image,rand(200,230),rand(200,230),rand(200,230))); // for($pos=0;$pos<$this->image_width;$pos+=8) imageline($this->res_image,$pos,0,$pos,$this->image_height,imagecolorallocate($this->res_image,rand(200,230),rand(200,230),rand(200,230))); } function Gen_Cod() { //generate rand cod : //mode:1 => 0-9 , mode:2 => 0-9 , a-z ($this->mode==1) ? $this->sec_cod=substr((string)rand(1000000000,9999999999),0,$this->cod_length) : $this->sec_cod=substr(md5(rand(1000000000,9999999999)),0,$this->cod_length); //set session : $_SESSION[$this->session_name] = $this->sec_cod ; //creat image : $this->res_image=imagecreatetruecolor( $this->image_width , $this->image_height ); //fill color: imagefilledrectangle($this->res_image,0,0,$this->image_width,$this->image_height,imagecolorallocate($this->res_image,255,255,255)); //write text : $this->Write_Text($this->sec_cod); //draw line : $this->Draw_Line(); //output : imagejpeg($this->res_image); header('content-type:image/jpeg'); //destroy: imagedestroy($this->res_image); } } 로그인 후 복사 2,php验证码类的调用示例: <?php session_start(); if(isset($_POST['captchacod'])){ if($_SESSION['login']==$_POST['captchacod'])echo'Your Entered Cod Was Correct<br>'; else echo'Your Entered Cod Was Incorrect<br>'; } ?> <img src="/static/imghw/default1.png" data-src="captcha.php?cap=login.png" class="lazy" alt="PHP 인증 코드 클래스 및 호출 예시 공유" > <form action="<?php echo $_SERVER['PHP_SELF']; //safe it later (xss)?>" method="post"> INPUT TEXT :<br> <input type="text" name="captchacod"><br> <input type="submit" value="check"><br> </form> 로그인 후 복사 |

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Alipay PHP ...

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

기사는 입력 유효성 검사, 인증 및 정기 업데이트를 포함한 취약점을 방지하기 위해 프레임 워크의 필수 보안 기능을 논의합니다.

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...
