php 图片验证码用javascript验证
现在我的图片验证是交到后台验证,感觉影响查询速度。如何交给javascript验证?
php生成页面代码如下:
<?php session_start(); //生成验证码图片 Header("Content-type: image/PNG"); $im = imagecreate(44,18); // 画一张指定宽高的图片 $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色 imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中 $vcodes = ""; srand((double)microtime()*1000000); //生成4位数字 for($i=0;$i<4;$i++){ $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色 $authnum=rand(1,9); $vcodes.=$authnum; imagestring($im, 5, 2+$i*10, 1, $authnum, $font); } $_SESSION['VCODE'] = $vcodes; for($i=0;$i<100;$i++) //加入干扰象素 { $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数 } ImagePNG($im); ImageDestroy($im); ?>
前台样式:
<form name="form1" method="post" action="719.php" > <p><label>电脑编号:</label><input name="username" type="text" size="20"></p> <p class="prmt"><label>用户密码:</label><input name="pass" type="password" size="20"> <input type="submit" name="Submit" value="查 询"></p> <p class="prmt"><label>验 证 码:</label><input name="ask" type="text" size="6"><img src="/static/imghw/default1.png" data-src="muth.php" class="lazy" id="refresh" onclick="document.getElementById('refresh')."/ alt="php 图片验证码用javascript验证" ></p> </form>
这样,后台里就能通过开启session_start();并与$_SESSION['VCODE']判断验证码是否正确。
我如何能够通过javascript做验证,而不需要php后台来验证。
回复讨论(解决方案)
通过javascript验证可以轻松的绕过或者说破解,不建议
一切用户能操作的验证 都是不靠谱的
那这样?先跳到中间页面,这个页面就只进行验证码判断,如果正确,再跳转到页面输出结果,否则,给出提示,回到原来那里输入页面?
sesssion 保存在服务端,前台如何能获取得到?
通过javascript做验证???
那要验证码干什么?
我通过js验证,只是不想用户又再点多一下,跳回来只是为了再输入正确的验证码,直接就在点表单的时候就验证了。
我有点看明白了 楼主你是提交的时候把验证码 用户名密码一起提交的 并且之前没有判断验证码是否正确,所以担心输错了又要重新输入用户名密码
一般这里采用ajax来做,当验证码输入框失去焦点后,获取输入的内容传递到后台进行对比,如果正确就在输入框右边打个勾 反制则打个X提示验证码错误.
输入正确后再一起提交到后台进行下一步的处理.
对
那我该怎么做呢?我什么都只是懂一点点
首先你得先了解一下 ajax 更便捷的是从jquery的ajax学起 20分钟内就能见效
http://www.baidu.com/s?wd=jquery+ajax 今天我也在纠结别的问题 不能帮你写全套代码了...
ajax完破
前面也遇到这个问题,后台判断验证码觉得麻烦。想用js,可是得不到验证码,后来想到把session中的验证码放到一个隐藏的标签里面,再用js。真心不好使啊,获得的验证码是上一次的,或者是刷新之前的,总是滞后,后来放弃了。
前面也遇到这个问题,后台判断验证码觉得麻烦。想用js,可是得不到验证码,后来想到把session中的验证码放到一个隐藏的标签里面,再用js。真心不好使啊,获得的验证码是上一次的,或者是刷新之前的,总是滞后,后来放弃了。
这个问题仔细想想就知道是什么原因了,你表单中隐藏标签中的值是页面初始化的值,而给用户看到的图形验证码的值是又新生成的,并且重新设置了验证码session值,所以是滞后一步。楼主的问题就像前面网友说使用ajax发起判断,具体的触发方式,我觉得是按键弹起的时候,加上验证码当时输入的长度来合理的触发ajax事件。
比如4位长的验证码,按键弹起时判断长度,到了4长度就ajax判断输入正确没有。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building
