Home Backend Development PHP Tutorial input button 一个很严重的有关问题

input button 一个很严重的有关问题

Jun 13, 2016 pm 01:32 PM
memcache order quot session

input button 一个很严重的问题
我在一个退款页面里面,有个按钮
按下这个按钮,会执行sql,就是把别人付过钱的总数退还到他们的网站账户里去。

问题就是,如果按一下这个cancel order是没问题的,浏览器需要1,2秒反应。但是连续按,发现退还的钱会叠加啊!

比如一个用户应该退10块钱,他点cancel order连续点了10下,那么他账户里就会多100块钱,应该不管他们点几下,退还的都是10块才对。

这应该怎么解决?

------解决方案--------------------
提交完,就黑了那个按钮。另外,使用session变量控制。提交的时候,对照一下,确定是否重复提交。
------解决方案--------------------
要是一般涉及到现金的支付页面的话,肯定是在表单里隐藏了一个订单ID,重复提交的问题是不会存在的,因为数据库做事务了。

这里如果你的应用是很普通的,就是为了防止重复留言,那么还是有点办法来实现的。因为PHP自身是做不了这个事务的,也就是检查ID是否被支付与之标记为支付这两个操作只有数据库可以保证事务原子性,另外一种办法就是memcache的原子加法属于一个巧妙手法。

这里id不借助session存储了,因为session_start之后session变量都是本地化的,php进程之间无法共享,所以只借助session_id把表单隐藏id存在memcache里。

刷新表单应该引发memcache里的id放在隐藏域里,提交表单应该引发memcache对该id原子加1,判断原子加的返回值是否为表单id+1,如果是就提交成功,否则提交失败。这是变相的借助memcache原子加法实现事务,因为原子加法避免了我们先取后加,而是原子的加1并返回结果,只要判断-1之后是否等于id即可,也是一门奇淫巧计了,这和幂等性什么的很类似,一些分布式无锁操作都是这么干的。
------解决方案--------------------
浏览器里面可以用disabled来禁用
建议服务端加个判断,不然别人模拟重复提交你就完了

Statement of this Website
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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to PHP Session cross-domain problem Solution to PHP Session cross-domain problem Oct 12, 2023 pm 03:00 PM

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

How to use Memcache in PHP development? How to use Memcache in PHP development? Nov 07, 2023 pm 12:49 PM

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

What are the differences between JavaScript and PHP cookies? What are the differences between JavaScript and PHP cookies? Sep 02, 2023 pm 12:29 PM

JavaScriptCookies Using JavaScript cookies is the most effective way to remember and track preferences, purchases, commissions and other information. Information needed for a better visitor experience or website statistics. PHPCookieCookies are text files that are stored on client computers and retained for tracking purposes. PHP transparently supports HTTP cookies. How do JavaScript cookies work? Your server sends some data to your visitor's browser in the form of a cookie. Browsers can accept cookies. If present, it will be stored on the visitor's hard drive as a plain text record. Now, when a visitor reaches another page on the site

PHP Session cross-domain and AJAX asynchronous communication optimization PHP Session cross-domain and AJAX asynchronous communication optimization Oct 12, 2023 am 09:22 AM

Optimization of asynchronous communication between PHPSession across domains and AJAX With the development of the Internet, cross-domain access and asynchronous communication have become common requirements in modern web application development. This article will focus on how to use PHPSession to achieve cross-domain access, and provide some optimization methods to improve the asynchronous communication efficiency of AJAX. 1. The problem of cross-domain access In Web development, when the browser initiates an HTTP request from a web page of one domain name, and then returns the response data belonging to another domain name, it will occur.

What are the reasons for session failure? What are the reasons for session failure? Oct 17, 2023 pm 05:01 PM

Reasons for session failure include session timeout, session number limit, session integrity check, server restart, browser or device problems, etc. Detailed introduction: 1. Session timeout: The server sets a default timeout for the Session. When the user does not interact with the server for a period of time, the Session will automatically expire; 2. Session number limit: The server has a number of Sessions for each user. A limit is set. When the number of Sessions created by a user exceeds this limit, the latest one will overwrite the oldest one and so on.

Master the Session authentication mechanism and security optimization in PHP Master the Session authentication mechanism and security optimization in PHP Aug 06, 2023 pm 04:17 PM

Master the Session authentication mechanism and security optimization in PHP. The Session authentication mechanism is a commonly used authentication method in Web development. In PHP, sessions are used to implement user identity authentication and permission control to protect users' sensitive information from being leaked. This article will introduce how to use sessions correctly in PHP and improve session security. Opening Session In PHP, we need to open session first to use its functions. use

How to use Memcache for efficient data reading and writing operations in PHP development? How to use Memcache for efficient data reading and writing operations in PHP development? Nov 07, 2023 pm 03:48 PM

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

See all articles