찾다
php教程PHP源码验证码使用

验证码使用

May 25, 2016 pm 05:15 PM
인증코드

php代码

<?php
session_start();
$length=4;
$mode=1;
$type=&#39;png&#39;;
$width=48;
$height=22;
$verifyName=&#39;verify&#39;;
$chars=&#39;ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789&#39;;
for($i=0;$i<$length;$i++){
  $str.= mb_substr($chars, floor(mt_rand(0,mb_strlen($chars)-1)),1);
}
$randval = $str;
$_SESSION[$verifyName]= md5(strtolower($randval));
$width = ($length*10+10)>$width?$length*10+10:$width;
if ( $type!=&#39;gif&#39; && function_exists(&#39;imagecreatetruecolor&#39;)) {
	$im = @imagecreatetruecolor($width,$height);
}else {
	$im = @imagecreate($width,$height);
}
$r = Array(225,255,255,223);
$g = Array(225,236,237,255);
$b = Array(225,236,166,125);
$key = mt_rand(0,3);

$backColor = imagecolorallocate($im, $r[$key],$g[$key],$b[$key]);    //背景色(随机)
$borderColor = imagecolorallocate($im, 100, 100, 100);                    //边框色
$pointColor = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));                 //点颜色

@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
$stringColor = imagecolorallocate($im,mt_rand(0,200),mt_rand(0,120),mt_rand(0,120));
// 干扰
for($i=0;$i<10;$i++){
	$fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
	imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);
}
for($i=0;$i<25;$i++){
	$fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
	imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pointColor);
}
for($i=0;$i<$length;$i++) {
	imagestring($im,5,$i*10+5,mt_rand(1,8),$randval{$i}, $stringColor);
}
//@imagestring($im, 5, 5, 3, $randval, $stringColor);
#Image::output($im,$type);
header("Content-type: image/".$type);
$ImageFun=&#39;image&#39;.$type;
if(empty($filename)) {
	$ImageFun($im);
}else{
	$ImageFun($im,$filename);
}
imagedestroy($im);
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 Mac 버전

SublimeText3 Mac 버전

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

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구