I have problem SIMILAR to preventing form data reposting, but not quite the same. That question has been answered many times. The advice given, like header redirects and sessions, didn’t work for me. Whether they failed because of my incorrect implementation, lack of experience solving this problem, or both, I don’t know.
I have an intranet web app that, when launched, extracts data from a different server, transforms it, and then loads it to a database local to the application. What happens is that if the user refreshes the main page, the ETL scripts run again and duplicate the data.
How can prevent the ETL scripts from re-running? For this app, there is no reason to refresh the page. Should I simply prevent refreshes altogether on that page, if that’s even possible? I’m probably overlooking something simple. So, I’m open to suggestions.
UPDATE:
I got this test code to work on the index.php page. So, I’m going to build on that to craft a solution. I’ll keep you posted.
session_start();
$_SESSION['views'] = 1; // store session data
echo "Pageviews = ". $_SESSION['views']; //retrieve data
I’ve outlined a very basic example for you of how you could use a session to make sure your scripts are only run once per visit (per user). The key point here is the script would still run more than once in the event of more than 1 user using the system.
To get around this I would simply use your local db to keep track of when the scripts were last run. So you could have a datetime column in your db that would keep track of when the last ‘run’ was performed.
This above way would make the number of users irrelevant as all checks will be performed against a central data set (i.e. your db). It would also probably be a bit more robust as it will be independent of browser and user.
Anyway here is a session (per user) method:
Let me know if I missed what you were trying to do or you want further explanations on anything?