Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't update DB if the user hits refresh.

Status
Not open for further replies.

max1x

Programmer
Jan 12, 2005
366
US
I don't have access to CGI::Session, and I'm not sure if I'm doing this right. But, this is what I have. What I'm trying to do is NOT have the DB update with the same record if user hits refresh...

From the source Page:
$cookie = (-name=>"myCookie", -value=>"$date", -expires=>"-1d");

Target Page:
use CGI;
$q = new CGI;
$cookieData = $q->cookie("myCookie");
$date = 'date';
chomp ($date);

print header (-cookie=>"$cookieData", -expires=>'-1d');

if ($cookieData eq $date) {
print "No Refresh allowed"
} else {
Update DB;
}

 
Code:
$cookie = (-name=>"myCookie", -value=>"$date", -expires=>"[b]+1d[/b]");
or
Code:
$cookie = (-name=>"myCookie", -value=>"$date", -expires=>"[b]+24h[/b]");

M. Brooks
 
Thanks M.Brooks.

+1d and +24h will keep the data valid for 1 day or 24 hours correct? So, the user can hit refresh and it will still update the records.

I want the results page to expire right away (hence -1d) so that the usres cannot hit refresh and update duplicate records.
 
The -1d option is not working for me, nor is "now"...Pleaes let me know if there are any other suggesitons...
 
Setting the cookie to expire "now" will set the cookie on the user's machine and immediately delete it. That's why M. suggested setting it to a positive value.

Since you're looking for a way to tell if a user just refreshed the page verses loaded it from scratch, what about creating the cookie and passing the value of the last URL visited? Then upon subsequent visits, you can check the cookie and if the value matches the page you're on, you skip the DB update... Otherwise, do the update.

- George
 
Thanks George...

Since this was kinda urget, I went a diff route and used redirect after showing the user that the data was uploaded successfully.

Not the best way to do it, but now I have time to play around with it more, while something is in place.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top