General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 15th, 2003, 09:06 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
Question Preventing data write on refresh.

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

Reply With Quote
  #2  
Old April 15th, 2003, 01:40 PM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Use cache busting at the top of the page.
PHP Code:
 header("Expires: Mon, 26 Jul 1997 01:00:00 GMT");
header("Last-Modified: "gmdate("D, d M Y H:i:s"). " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: post-check=0,pre-check=0");
header("Cache-Control: max-age=0");
header("Pragma: no-cache"); 

Reply With Quote
  #3  
Old April 15th, 2003, 03:48 PM
Juice Terry Juice Terry is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 4 Juice Terry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Baines,

THere is an O'reilly article that suggests a solution to this problem. Look at number 6. at

URL

JT

Reply With Quote
  #4  
Old April 15th, 2003, 03:48 PM
*JaH* *JaH* is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 14 *JaH* User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the info Torrent Didn't know that

Reply With Quote
  #5  
Old April 16th, 2003, 04:03 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
Question But is there a "Correct" method?

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

Reply With Quote
  #6  
Old April 16th, 2003, 04:28 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
OMG Kevin yank!

no wonder your having problems!

Reply With Quote
  #7  
Old April 16th, 2003, 04:48 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
Quote:
Originally posted by Ben Rowe
OMG Kevin yank!

no wonder your having problems!


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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Preventing data write on refresh.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT