search
HomeWeb Front-endJS TutorialURL rewriting to implement verification code transformation
URL rewriting to implement verification code transformationAug 07, 2017 pm 04:42 PM
transformaccomplishverify

Rewriting URL mechanism: In order to ensure that the address of a URL is unique, the parameters passed to the server can be different each time. Here, when implementing the function of changing the verification code, the value of the parameter list is changed to refresh. Please refer to this article for the detailed code

Rewriting URL mechanism: In order to ensure that the address of a URL is unique, the parameters passed to the server can be different each time.

The header information of the data request can be analyzed: the header information includes http protocol, IP address, port number, project name, and request parameter list. If the resources you want to access do not change, you can only change the parameters. Continuous table.

When implementing the function of changing the verification code, the value of the parameter list is changed to refresh.

Detailed code implementation:


<%@page import="javax.imageio.ImageIO"%> 
<%@page import="java.awt.Font"%> 
<%@page import="java.awt.Color"%> 
<%@page import="java.awt.Graphics"%> 
<%@page import="java.awt.image.BufferedImage"%> 
<%@ page contentType="image/jpeg" language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<% 
int w=100; 
int h=30; 
BufferedImage bi=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB); 
Graphics g=bi.getGraphics(); 
Color c=g.getColor(); 
Font f=g.getFont();  
Random r=new Random(); 
Color bg=new Color(150+r.nextInt(100),150+r.nextInt(100),150+r.nextInt(100)); 
g.setColor(bg); 
g.fillRect(0, 0, w, h); 
String code=""; 
for(int i=1;i<=4;i++){ 
int num=r.nextInt(10); 
code=code+num; 
Color num_c=new Color(r.nextInt(150),r.nextInt(150),r.nextInt(150)); 
g.setColor(num_c); 
g.drawString(String.valueOf(num), 20*i, h/2); 
} 
request.getSession().setAttribute("code", code); 
//清空缓存 
response.setHeader("pragma", "bo-cache"); 
response.setHeader("cache-control", "bo-cache"); 
response.addDateHeader("expires", 0); 
ImageIO.write(bi, "jpeg", response.getOutputStream()); 
out.close(); 
 %>

Add login page:


<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
 <head> 
  <base href="<%=basePath%>" rel="external nofollow" > 
  <title>My JSP &#39;login.jsp&#39; starting page</title> 
  <meta http-equiv="pragma" content="no-cache"> 
  <meta http-equiv="cache-control" content="no-cache"> 
  <meta http-equiv="expires" content="0">   
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
  <meta http-equiv="description" content="This is my page"> 
  <!-- 
  <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" > 
  --> 
  <script type="text/javascript"> 
function changeimage(){ 
var d=new Date();//生成时间戳, 
document.getElementById("img").src="image.jsp?t="+d;//由变化的时间使参数连表发生变化,url重写 
} 
</script> 
 </head> 
 <body> 
 <font color="red">${requestScope.msg }</font> 
  <form action="loginServlet" method="post"> 
  name:<input type="text" name="uname"><br> 
  pwd:<input type="pwd" name="upwd"><br> 
  code:<input type="text" name="code" size="5"><img src="/static/imghwm/default1.png"  data-src="image.jsp "  class="lazy"  id="img" alt="" ><a onclick="changeimage()">换一张</a><br> 
  <input type="submit" > 
  </form> 
 </body> 
</html>

Use of time changes , each time a timestamp is generated and passed to the requested URL, the purpose of rewriting the URL is achieved, thus realizing the refresh function of changing one page.

The above is the detailed content of URL rewriting to implement verification code transformation. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
golang中如何验证输入是否为大写字母golang中如何验证输入是否为大写字母Jun 24, 2023 am 09:06 AM

Golang是一门高性能、现代化的编程语言,在日常开发中经常涉及到字符串的处理。其中,验证输入是否为大写字母是一个常见的需求。本文将介绍在Golang中如何验证输入是否为大写字母。方法一:使用unicode包Golang中的unicode包提供了一系列函数来判断字符的编码类型。对于大写字母,其对应的编码范围为65-90(十进制),因此我们可以使用unicod

golang中如何验证输入是否为全角字符golang中如何验证输入是否为全角字符Jun 25, 2023 pm 02:03 PM

在golang中,验证输入是否为全角字符需要用到Unicode编码和rune类型。Unicode编码是一种将字符集中的每个字符分配一个唯一的数字码位的字符编码标准,其中包含了全角字符和半角字符。而rune类型是golang中用于表示Unicode字符的类型。第一步,需要将输入转换为rune类型的切片。这可以通过使用golang的[]rune类型进行转换,例如

PHP正则表达式验证特定字符串开头结尾的方法PHP正则表达式验证特定字符串开头结尾的方法Jun 24, 2023 am 11:20 AM

PHP是一种非常流行的编程语言,常用于Web开发。在PHP开发中,我们经常会遇到需要验证字符串的情况。其中,正则表达式是一种非常常用的方法。在对字符串进行验证时,我们经常需要验证字符串是否以特定字符或字符串开头或结尾。本文将介绍如何使用PHP正则表达式来验证字符串的开头或结尾。验证字符串开头在PHP中,通过正则表达式验证字符串开头,我们可以使用"^"符号来表

golang中如何验证输入是否全部为中文字符golang中如何验证输入是否全部为中文字符Jun 24, 2023 am 09:16 AM

随着时代的发展,我们越来越注重对数据的校验,特别是对用户输入的校验。对于语言类的校验,如何准确判定输入是否全部为中文字符成为了一个重要问题。而在golang中,我们可以借助unicode包和regexp包来实现这一需求。一、unicode包unicode包提供了一系列对于unicode的核心支持。我们可以使用这个包中的函数来准确地判断一个字符是否为中文字符。

在PHP中使用Google reCAPTCHA进行验证在PHP中使用Google reCAPTCHA进行验证Jun 19, 2023 pm 05:38 PM

在现代网络世界中,网站的安全性以及用户隐私的保护越来越成为重要话题。其中,人机验证这一技术方法已经成为防范恶意攻击行为的不可或缺的方式之一。GooglereCAPTCHA,是一个被广泛应用于人机验证的工具,其概念已经深入人心,甚至在我们每天使用的许多网站上都能够看到其存在的身影。在本文中,我们将探讨如何在PHP中使用GooglereCAPTCHA进行验证

PHP正则表达式验证正整数的方法PHP正则表达式验证正整数的方法Jun 24, 2023 am 08:55 AM

在PHP中,正则表达式可以用于验证和处理字符串。验证正整数的正则表达式如下所示:$pattern=&quot;/^[1-9]d*$/&quot;;其中,^表示开头,$表示结尾,[1-9]表示第一个字符必须是1-9之间的数字,d表示其他字符必须是数字,*表示0个或多个。因此,这个正则表达式可以匹配任意一个正整数。下面是一个完整的例子,演示如何使用正则表达式

手机号码验证登录注册的PHP实现指南手机号码验证登录注册的PHP实现指南Aug 17, 2023 pm 03:18 PM

手机号码验证登录注册的PHP实现指南一、概述手机号码验证是现代互联网应用中常见的功能之一,它不仅可以用于用户注册和登录验证,还可以用于短信验证码发送等场景。本文将介绍如何使用PHP语言实现手机号码验证登录注册功能。二、环境要求在开始编写代码之前,我们需要确保以下环境已经准备就绪:PHP环境:PHP的版本需达到5.6或以上。数据库:本文使用MySQL数据库作为

golang中如何验证输入是否为有效的Html标签golang中如何验证输入是否为有效的Html标签Jun 24, 2023 am 08:11 AM

Go语言是一种快速、高效和强类型的编程语言,被广泛应用于网络服务开发、云计算、数据科学、互联网金融等领域。在Web应用开发中,输入验证是一个非常重要的问题,其中验证输入中的HTML标签是否有效是一个常见的需求。下面我们将介绍如何在Go语言中实现这一需求。HTML标签在Web页面中扮演着重要角色,它们定义了页面的结构、样式和交互行为。但在处理用户输入时,我们需

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools