How to make the submitted page can not be retracted back Beerium [original]

zhaozj2021-02-16  184

The back button of the browser allows us to easily return the previously visited page, which is undoubtedly useful. But sometimes we have to close this feature to prevent users from chaos a predetermined page access order. This article describes the various browser-free button schemes available on the network to analyze their respective advantages and disadvantages and applications. First, the overview has asked many people, "How can I disable the 'browser's back button?", Or "How to prevent the user from clicking the back button to return to the previously viewed page?" In the ASP Forum, this question is also asked One of the most problems. Unfortunately, the answer is very simple: we can't disable the back button of the browser. At first I feel unbelievable for someone who wants to disable the browser. Later, I saw that there were so many people who would like to disable this back button, I also relieved (only the back button if I want to disable, do not include the browser's forward button). Because the user submits the form by default, you can return to the form page by the back button (instead of using the Edit button!), Then edit again and submit the table One-way database into new records. This is what we don't want to see. So I decided to figure out how to avoid this. I have visited many websites, referring to various implementation methods described by these websites. If you regularly access the ASP programming website, some of this article you may have already seen. The task of this article is to introduce all possible methods to everyone, then find the best way! Second, it is forbidden to cache in many scenarios I found, one of which is recommended to prohibit page cache. Specifically, the server-side script is used, as shown below: <% response.buffer = true response.expiresabsolute = 5 () - 1 response.expires = 0 response.cachecontrol = "no-cache"%> This method is very effective! It forces the browser to re-access the server download page instead of reading the page from the cache. When using this method, the programmer's main task is to create a session-level variable, determine if the user still views the page that is not suitable for passing the back button. Since the browser no longer caches this page, the browser will re-download the page when the user clicks the back button. At this time, the program can check the session variable to see if the user should be allowed to open this page. For example, suppose we have the following form: <% response.buffer = true response.expiresabsolute = 5 () - 1 response.expires = 0 response.cachecontrol = "no-cache" if len (session The user has accessed the current page and is now returned again. & Single; Clear the session variable to redirect the user to the login page.

Session ("FirstTimetopage" = "" "Response.Redirect" /Bar.asp "response.end end if & sales; if the program runs here, the user can view the current page & SINGLE; the following start creating a form%>

We use the session variable firstttimetopage to check if the user is the first time to access the current page. If it is not the first time (ie, "" "") contains a value), then we clear the value of the session variable and then reallite the user to a start page. In this way, when the form is submitted (at this time, we must give the firstTIMETOPAGE a value. That is, in somepage.asp we need to add the following code: Session ("firsttimetopage") = "no", users who have opened somepage.asp If you click the back button, the browser will re-request the server download page, server check To the Session ("FirstTIMETOPAGE") contains a value, then clear the session ("FirstTimetopage) and redirect the user to other pages. Of course, all this requires a user to enable cookies, otherwise the conversation variable will be invalid. (For more description of this problem, see for session variables to work, MUST THE Web Visitor HAVE COOKIES ENABLED?) In addition, we can also use client code to make your browser no longer cache web page: If you use the above method to force your browser to no longer caching the web page, you must pay attention to the following: "Pragma: no-cache" only prevents the browser cache page only when using secure connection. For pages that are not secure protected, "Pragma: No-Cache" is considered to be the same as "Expires: -1". At this point, the browser is still cached, but marks the page as an immediate expiration. In IE 4 or 5, the "Cache-Control" Meta Http-Equiv flag will be ignored and does not work. In practical applications, we can add all of these code. However, since this method cannot be applied to all browsers, it is not recommended. But if you are in an intraNET environment, the administrator can control which browser used, I think someone will use this method.

转载请注明原文地址:https://www.9cbs.com/read-8084.html

New Post(0)