Jump to content

Inhibit Refresh & Back Buttons


DickDeeds

Recommended Posts

I've written a program that deals with finances. The entry page (datain.php) calls a class (datarec.cls) to record each entry and then returns to datain.php for the next entry.The problem, after recording if somone hit the refresh or back button it records an addition entry each time the button is pressed. Obviously, this is extremely dangerious in a financial program.Does anyone have code or a method to prohibit this?TIA,###### Deeds

Link to comment
Share on other sites

One way to do it would be to save the last transaction in the user's session, and if you get a request to add a transaction compare it with the previous one first. You can't disable the browser's functionality, you just need to find a way to detect when it happens. Another way is to redirect after adding the transaction, if they refresh a redirect it won't resubmit.

Link to comment
Share on other sites

One way to do it would be to save the last transaction in the user's session, and if you get a request to add a transaction compare it with the previous one first. You can't disable the browser's functionality, you just need to find a way to detect when it happens. Another way is to redirect after adding the transaction, if they refresh a redirect it won't resubmit.
First,Thanks for the response.I tried using $_SESSION variables in both the class model and the php module. So I guess my question(s) are:1. How do you compare?? That shows I don't really understand what the browser is doing. Evidently, it does not cycle through the php or class modules.2. How do you redirect?TIA###### Deeds
Link to comment
Share on other sites

Redirection through <meta> tags will break the Back button. I discourage their use.The correct way to redirect is in PHP:

header("Location: file.php");

Link to comment
Share on other sites

The session is implemented just as an array, so anything you save in the session will be in the $_SESSION array. Comparing is the same as anything else, you just use the comparison operators to check for equality. Make sure to use session_start on every page. This has an example of setting session variables on one page and reading them on another:http://www.php.net/manual/en/function.session-start.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...