PHP 输出session 验证码与图片不同步,图片总是快一步,求解!解决方案
PHP 输出session 验证码与图片不同步,图片总是快一步,求解!
PHP 输出session 验证码与图片不同步,图片总是快一步,求解!
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> session_start(); function random($len) { $srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; mt_srand(); $strs=""; for($i=0;$i
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <img src="/static/imghw/default1.png" data-src="captcha.php" class="lazy" style="max-width:90%" style="max-width:90%" border="1" onclick="this.+Math.random()" style="cursor: pointer; vertical-align:middle" title="看不清?点击更换!" alt=" PHP 输出session 验证码与图片不同步,图片总是快一步,求解!解决方案 " >
------解决方案--------------------
这个问题很诡异,最好的方法就是分开。
试试这个吧
checkcode.class.php
- PHP code
<?php /** * 生成验证码 * 类用法 * $checkcode = new checkcode(); * $checkcode->doimage(); * //取得验证 * $_SESSION['code']=$checkcode->get_code(); session_start(); include './checkcode.class.php'; $checkcode = new checkcode('C:\WINDOWS\Fonts\ARIAL.TTF'); $checkcode->doimage(); $_SESSION['code']=$checkcode->get_code(); */ class checkcode { //验证码的宽度 public $width=130; //验证码的高 public $height=50; //设置字体的地址 private $font; //设置字体色 public $font_color; //设置随机生成因子 public $charset = 'abcdefghkmnprstuvwyzABCDEFGHKLMNPRSTUVWYZ23456789'; //设置背景色 public $background = '#EDF7FF'; //生成验证码字符数 public $code_len = 4; //字体大小 public $font_size = 20; //验证码 private $code; //图片内存 private $img; //文字X轴开始的地方 private $x_start; function __construct($fontpath) { $this->font =$fontpath; } /** * 生成随机验证码。 */ protected function creat_code() { $code = ''; $charset_len = strlen($this->charset)-1; for ($i=0; $icode_len; $i++) { $code .= $this->charset[rand(1, $charset_len)]; } $this->code = $code; } /** * 获取验证码 */ public function get_code() { return strtolower($this->code); } /** * 生成图片 */ public function doimage() { $code = $this->creat_code(); $this->img = imagecreatetruecolor($this->width, $this->height); if (!$this->font_color) { $this->font_color = imagecolorallocate($this->img, rand(0,156), rand(0,156), rand(0,156)); } else { $this->font_color = imagecolorallocate($this->img, hexdec(substr($this->font_color, 1,2)), hexdec(substr($this->font_color, 3,2)), hexdec(substr($this->font_color, 5,2))); } //设置背景色 $background = imagecolorallocate($this->img,hexdec(substr($this->background, 1,2)),hexdec(substr($this->background, 3,2)),hexdec(substr($this->background, 5,2))); //画一个柜形,设置背景颜色。 imagefilledrectangle($this->img,0, $this->height, $this->width, 0, $background); $this->creat_font(); $this->creat_line(); $this->output(); } /** * 生成文字 */ private function creat_font() { $x = $this->width/$this->code_len; for ($i=0; $icode_len; $i++) { imagettftext($this->img, $this->font_size, rand(-30,30), $x*$i+rand(0,5), $this->height/1.4, $this->font_color, $this->font, $this->code[$i]); if($i==0)$this->x_start=$x*$i+5; } } /** * 画线 */ private function creat_line() { imagesetthickness($this->img, 3); $xpos = ($this->font_size * 2) + rand(-5, 5); $width = $this->width / 2.66 + rand(3, 10); $height = $this->font_size * 2.14; if ( rand(0,100) % 2 == 0 ) { $start = rand(0,66); $ypos = $this->height / 2 - rand(10, 30); $xpos += rand(5, 15); } else { $start = rand(180, 246); $ypos = $this->height / 2 + rand(10, 30); } $end = $start + rand(75, 110); imagearc($this->img, $xpos, $ypos, $width, $height, $start, $end, $this->font_color); if ( rand(1,75) % 2 == 0 ) { $start = rand(45, 111); $ypos = $this->height / 2 - rand(10, 30); $xpos += rand(5, 15); } else { $start = rand(200, 250); $ypos = $this->height / 2 + rand(10, 30); } $end = $start + rand(75, 100); imagearc($this->img, $this->width * .75, $ypos, $width, $height, $start, $end, $this->font_color); } /** * 输出图片 */ private function output() { header("content-type:image/png\r\n"); imagepng($this->img); imagedestroy($this->img); } } <div class="clear"> </div>

핫 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)

뜨거운 주제











많은 사용자들이 스마트 시계를 선택할 때 Huawei 브랜드를 선택하게 됩니다. 그 중 Huawei GT3pro와 GT4가 가장 인기 있는 선택입니다. 두 제품의 차이점을 궁금해하는 사용자가 많습니다. Huawei GT3pro와 GT4의 차이점은 무엇입니까? 1. 외관 GT4: 46mm와 41mm, 재질은 유리 거울 + 스테인레스 스틸 본체 + 고해상도 섬유 후면 쉘입니다. GT3pro: 46.6mm 및 42.9mm, 재질은 사파이어 유리 + 티타늄 본체/세라믹 본체 + 세라믹 백 쉘입니다. 2. 건강한 GT4: 최신 Huawei Truseen5.5+ 알고리즘을 사용하면 결과가 더 정확해집니다. GT3pro: ECG 심전도, 혈관 및 안전성 추가

Golang을 사용하여 개발하거나 학습하는 과정에서 undefound:rand.Seed라는 오류 메시지가 나타날 수 있습니다. 이 오류는 일반적으로 난수 생성기를 사용해야 할 때 발생합니다. Golang에서는 rand 패키지의 함수를 사용하기 전에 난수 시드를 설정해야 하기 때문입니다. 이 문서에서는 이 오류를 해결하는 방법을 설명합니다. 1. math/rand 패키지를 도입하려면 먼저 math/rand 패키지를 코드에 도입해야 합니다. 존재하다

Windows 11에서 캡처 도구가 작동하지 않는 이유 문제의 근본 원인을 이해하면 올바른 솔루션을 찾는 데 도움이 될 수 있습니다. 캡처 도구가 제대로 작동하지 않는 주요 이유는 다음과 같습니다. 초점 도우미가 켜져 있습니다. 이렇게 하면 캡처 도구가 열리지 않습니다. 손상된 응용 프로그램: 캡처 도구가 실행 시 충돌하는 경우 응용 프로그램이 손상되었을 수 있습니다. 오래된 그래픽 드라이버: 호환되지 않는 드라이버가 캡처 도구를 방해할 수 있습니다. 다른 응용 프로그램의 간섭: 실행 중인 다른 응용 프로그램이 캡처 도구와 충돌할 수 있습니다. 인증서가 만료되었습니다. 업그레이드 프로세스 중 오류로 인해 이 문제가 발생할 수 있습니다. 이 문제는 대부분의 사용자에게 적합하며 특별한 기술 지식이 필요하지 않습니다. 1. Windows 및 Microsoft Store 앱 업데이트

Pygame의 글꼴 텍스트와 글꼴 Pygame은 텍스트 그리기 목적을 달성하기 위해 pygame.font 모듈을 사용하여 글꼴 개체를 만듭니다. 이 모듈의 일반적으로 사용되는 메서드는 다음과 같습니다: 이름 설명 pygame.font.init() 글꼴 모듈 초기화 pygame.font.quit() 글꼴 모듈 초기화 해제 pygame.font.get_init() 글꼴 모듈이 초기화되었는지 확인하고 부울 값을 반환합니다. pygame.font.get_default_font()는 기본 글꼴의 파일 이름을 가져옵니다. 시스템에서 글꼴의 파일 이름을 반환합니다. pygame.font.get_fonts()는 모두 가져옵니다.

1부: 초기 문제 해결 단계 Apple 시스템 상태 확인: 복잡한 솔루션을 살펴보기 전에 기본 사항부터 시작해 보겠습니다. 문제는 귀하의 기기에 있는 것이 아닐 수도 있습니다. Apple 서버가 다운되었을 수도 있습니다. Apple의 시스템 상태 페이지를 방문하여 AppStore가 제대로 작동하는지 확인하세요. 문제가 있는 경우 Apple이 문제를 해결하기를 기다리는 것뿐입니다. 인터넷 연결 확인: "AppStore에 연결할 수 없음" 문제는 때때로 연결 불량으로 인해 발생할 수 있으므로 인터넷 연결이 안정적인지 확인하십시오. Wi-Fi와 모바일 데이터 간을 전환하거나 네트워크 설정을 재설정해 보세요(일반 > 재설정 > 네트워크 설정 재설정 > 설정). iOS 버전을 업데이트하세요.

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Go 동시 프로그래밍에서 난수 생성 동기화: 뮤텍스(sync.Mutex)를 사용하여 rand.Rand 난수 생성기에 대한 액세스를 제어합니다. 각 고루틴은 난수를 생성하기 전에 뮤텍스 잠금을 획득하고 생성 후 뮤텍스 잠금을 해제합니다. 이렇게 하면 한 번에 하나의 고루틴만 난수 생성기에 액세스할 수 있어 데이터 경합이 제거됩니다.

rand() 함수는 각 호출에서 동일한 초기 시드를 사용합니다. 기본 초기 시드는 운영 체제의 시간에서 가져오지만 정확도는 마이크로초에 불과합니다. 즉, 매우 짧은 시간 내에 많은 rand() 함수 호출이 동일한 초기 시드를 사용하여 동일한 난수 생성이 발생합니다. 그렇다면 이 문제를 해결하는 방법은 무엇입니까?
