|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi Guys (and Girls)
![]() Being from the “Kevin Yank School of PHP”, I tend to write multi-function pages. A single script that will display a form, then validate the data and write the data to a database before displaying another option… All works well until someone hits REFRESH. You can guess what’s coming next. On a refresh, the same data is again written to the database as the POST data is preserved and acted upon. As far as I can see, there are two possible answers to the problem. 1) Remove the logic from the script completely. Have the form call the logic script and the logic script call the form. That way, if the page is refreshed, only the form is refreshed, not the logic. 2) Set some sort of session variable when the data is written. Checking the state of the variable before writing could prevent the data from being written again following a refresh. I’m happy to go either way but am wondering if there is a “preferred” method or indeed if there is another option all together. You thoughts please. Kind regards Baines |
|
#2
|
|||
|
|||
|
Use cache busting at the top of the page.
PHP Code:
|
|
#3
|
|||
|
|||
|
Baines,
THere is an O'reilly article that suggests a solution to this problem. Look at number 6. at URL JT |
|
#4
|
|||
|
|||
|
Thanks for the info Torrent
Didn't know that ![]() |
|
#5
|
|||
|
|||
|
Thanks JT
The O’Reilly solution is exactly what I was talking about in my original question in so much as it separates the logic from the display script. He has described it in much better terms than I did. ![]() What I’m really after is your thoughts on which is the better method? Is it better to have a single, multi-function script or several smaller scripts divided in to logic and output? As for the Cache Busting option, Torrent I assume that this will not have any effect on any session variables I’ve set. Some of these pages are part of an intranet and security information is passed from script to script allowing selected access according to your security level. I’m coming down on the side of splitting the scripts up in to logic and display and using the header option as described by O’Reilly but am open to suggestions. Thanks for you thoughts guys Regards Baines |
|
#6
|
|||
|
|||
|
OMG Kevin yank!
no wonder your having problems! |
|
#7
|
|||
|
|||
|
Quote:
LMAO ![]() Hi Ben, nice of you to contribute!!! We all have to start somewhere, it’s just that some of us start further down the ladder than others, plus the fact I like a challenge. Despite this, I am getting there and beginning to product some nice stuff mainly due to the fact that I found Devarticles soon after buying THAT book. I’m getting to the point that I want to start making my code more readable and as the current project will need to be maintained long after my departure, I’m interested in applying some standards (this is a first for me!!) Any thoughts gratefully received Your humble student Baines |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Preventing data write on refresh. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|