PHP prevents refreshing page repeat submissions

Source: Internet
Author: User

As a phper, we are in the development and learning of PHP process, it is inevitable to often accept processing form data, however, when processing the form there will always be a problem, bothering everyone, refresh the page repeatedly submitted questions. How do I prevent pages from being refreshed repeatedly?

In fact, in the PHP learning we will have a lot of methods, such as the simplest, we can adopt, after the successful submission of the method of jump. But doing this, sometimes, there will be a lot of bottlenecks, for example, if our page has a lot of content to be loaded, especially with a lot of background dealing with, so if the jump to reload the page, it may cause pressure on the server. Here we can use another method to prevent refreshing the page to repeat the submission, so that everyone better learn PHP.

We can use session to solve. We first create a session, and assign a value, the first submission after the change of the session's value, when the second time this content submission, if not our assignment, it is not processing the data passed over.
Such as:
<?php
Session_Start ();
$_session[' num '] = 0;
if (Isset ($_post[' action '] && $_post[' action ']== ' submit ')) {
if ($_session[' num '] = = 0) {
Echo ' <a href= '. $_server[' php_self '. ' > ' Please try again </a>; '
$_session[' num '] = 1;
}else{
Echo ' You have already submitted, please do not repeat ';
}
}
?>
The front page is not given, I believe we all know how to write in front. In fact, such as to prevent the page to refresh the repeated submission of the method, there are many, in the future of the exchange of PHP learning, will be more enumerated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.