Author Topic: Preventig Refresh  (Read 2735 times)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Preventig Refresh
« on: May 24, 2007, 03:13:39 AM »
Yeah, I need a way to prevent a user from refreshing a page.
There will be a link on the page to access the same page again, but the user has to wait a bit beofre he can click the link. So I need to disable/prevent user-refreshing.

Anyone know how to do that?

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Preventig Refresh
« Reply #1 on: May 24, 2007, 03:37:15 AM »
Umm, you could set a time limit on the number of page views.
So, the next time the use visits a page, you could check when was the last time the user viewed the page.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #2 on: May 24, 2007, 04:15:11 AM »
I'm more looking for a way to pop up a box when the user tries to refresh the page.

So he could klick the link over and over again, but when he refreshes the page he gets an error. Mainly I'm trying to prevent bot-usage. Or won't that work at all?

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Preventig Refresh
« Reply #3 on: May 24, 2007, 04:21:54 AM »
Well, bots could also click the link, and the only way I know of stopping a refresh like that is using javascrip, and people can disable javascript.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #4 on: May 24, 2007, 09:29:07 AM »
how would I do it with JS? (I never really got interested in JS, tho)

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: Preventig Refresh
« Reply #5 on: May 24, 2007, 09:49:11 AM »
Just put a time limit.. maybe put the last time visited in the session... may have to encrypt it so it can't be hijacked though..


if they go to the page and the last time they visited isn't longer than the limit, don't do any processing.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Preventig Refresh
« Reply #6 on: May 24, 2007, 01:30:35 PM »
Well, actually, I don't know how to do it with JS. I don't think it's possible after a quick search on google. What I meant was that javascript is probably one of the few scripting languages that could actually interfere with browser activity. (Maybe VBScript could work? I never learnt VBScript)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #7 on: May 24, 2007, 03:17:01 PM »
well, I guess I'll have to go with the time-set option.

But what about a POST variable that needs to be checked? But with firefoy these values are stored and reused on refresh. Any ideas here maybe?

Offline dvd871

  • Level 21
  • *
  • Posts: 238
  • Reputation: +7/-0
    • View Profile
    • Dominion Siege
Re: Preventig Refresh
« Reply #8 on: May 24, 2007, 10:29:29 PM »
You can also use cookies and set the expire time for a page.  Problem is like was mentioned with javascript, some people disable cookies.  The way around that is to explicitly tell users that they must have cookies and/or javascript installed for your game.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Preventig Refresh
« Reply #9 on: May 25, 2007, 05:18:53 AM »
But what about a POST variable that needs to be checked? But with firefoy these values are stored and reused on refresh. Any ideas here maybe?

Here's an article on how to stop POST refreshes:
http://www.thefutureoftheweb.com/blog/get-redirect-after-post

It just processes the POST information, then redirects to the same page with a GET request instead. Then if the user refreshes the page, it won't have any POST information attached to it.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #10 on: May 25, 2007, 05:57:53 AM »
thanks, I'll look into it as soon as I got some spare time on my hands.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #11 on: May 25, 2007, 08:57:54 AM »
Bah, I'll just drop the whole idea and find another way around it :)

Offline harntrox

  • Level 3
  • *
  • Posts: 9
  • Reputation: +1/-0
    • View Profile
    • Galaktikon
Re: Preventig Refresh
« Reply #12 on: June 18, 2007, 12:24:41 PM »
you can do it with php, mysql, and a session variable. javascript is optional but gives you better output.

the idea is, using mysql,  you keep a counter associated with the user for each page you want to track.
then you set a session variable to page_x_refresh_allowed=1.   then when they refresh, you set the value in mysql to 0.

upon attempts to refresh, reference the session var page_x_refresh_allowed,  then you have php output a different javascript onload() event handler to show window or hide a div or whatever to notify user that refresh is disabled.  even with javascript *off* you can get it to show a different html image with /noscript.

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Preventig Refresh
« Reply #13 on: June 24, 2007, 05:45:22 AM »
All the current Mafia type of games out there right now deal with the same issue.

You select a crime, hit submit, see result of said crime, then must wait X amount of time to commit another crime.

Now if you have something in your game that is similiar you have not only the refresh problem *BUT* the Opera browser has this nifty little feature that'll let you auto "do" something every X seconds / minutes built right into it, Firefox can also do this but it requires and extension loaded into it. The first problem is easy when a player hits the submit button it checks a timestamp, if the timestamp has expired do the action if not show a warning "You must wait another X min/sec"

To get around the auto scripters I added a CAPTCHA prompt every X amount of hits by the player to that page. There are a bunch of examples out there that show how to add CAPTCHA to a PHP page ;)

Creating online addictions, one game at a time:

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Preventig Refresh
« Reply #14 on: June 24, 2007, 05:58:42 AM »
Yeah, I was afraid that there might be something like this (opera + firefox ext).

Even more of a reason to have dropped it :)

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: Preventig Refresh
« Reply #15 on: June 28, 2007, 10:45:39 AM »
Good idea codestryke.. I see game like bootleggers implemented this idea..

But, one thing.. It's really frustrating to see coders preventing the ability to refresh to do simple crimes..etc..
The user should be able to do it.. they will not sit the whole day just to earn shitty $ for the sake of increasing their stats for promotion..etc.. Auto refresh DO help users!!
Simple stuffs like this, should be allowed!
(Just my point of view ;) )

Offline Carrion

  • Level 4
  • *
  • Posts: 13
  • Reputation: +0/-0
    • View Profile
Re: Preventig Refresh
« Reply #16 on: June 30, 2007, 03:59:29 PM »
what about creating a new window? this would allow you to controll what is added to the window. statusbar, menubar, etc...

I think you could then add an event function in javascript that will capture for browser activity like the refresh  and check the timer variable for a proper value.

this is just an idea, not sure it would work. and you still have the issue that js is turned off. to counter that have the server test that js is enabled. if not log the user out, ending their session and return them to the login screen. I would think people will get the idea after a while to stop jacking with the js settings.

Offline Dasein Fiasco

  • Level 15
  • *
  • Posts: 132
  • Reputation: +2/-0
    • View Profile
    • Travis Dunn
Re: Preventig Refresh
« Reply #17 on: July 04, 2007, 12:37:57 PM »
Generally speaking, it would be best to impose any refresh limitations in the code's logic, not through some artificial javascript-based browser manipulation. At the very best, you might create a solution that works today for the small number of browsers and plugins you're able to test, but with no guarantee that it will work tomorrow.

In other words, never delegate any sort of business logic to the client. If something like attacks-per-minute is important to your game's restrictions, impose that restriction through the code, and store any related game-state information on your server.
Personal Site: www.travisdunn.com
There is neither speech nor language but their voice is heard among them

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Preventig Refresh
« Reply #18 on: July 04, 2007, 01:40:22 PM »
Good idea codestryke.. I see game like bootleggers implemented this idea..

But, one thing.. It's really frustrating to see coders preventing the ability to refresh to do simple crimes..etc..
The user should be able to do it.. they will not sit the whole day just to earn shitty $ for the sake of increasing their stats for promotion..etc.. Auto refresh DO help users!!
Simple stuffs like this, should be allowed!
(Just my point of view ;) )
Depends on the game though...

On Cypher where there is a start and end point I added auto-join to multi-player missions because ppl can't always be online and it is a game that does end and reward the person with the most xp after the round.

Mafia games though are not like that. There is end point and they are based mostly on fostering a community rather then playing a game with and end point. In that case I prevent auto-refreshers because it's not about getting the most crimes or whatever it's about sitting and waiting and thus sorta pushing a player to check out the forums or chat and become a part of the community.

Plus there is a huge un-fair advantage given to those that have DSK/Cable or whatever to those still on dial up.. Yes there are a still GREAT number of ppl on dial up. So scripts like that put player's at a huge disadvantage.

IMHO ;)
Creating online addictions, one game at a time:

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Preventig Refresh
« Reply #19 on: September 17, 2007, 04:07:39 PM »
Anti auto-refresh algo. (not effective against bots, just versus simple refresh)
1) save random variable in a session
2) put the variable in post/get code
3) check if the variable posted through post/get is the same as previously stored variable
Very simple, like 3 lines of code or so.


Offline Equinox

  • Game Owner
  • Level 10
  • *
  • Posts: 58
  • Reputation: +2/-0
    • View Profile
    • Equinox Gaming Solutions
Re: Preventig Refresh
« Reply #20 on: October 12, 2007, 03:02:21 AM »
I wonder is there any way to code so that JS must be enabled to access the pages? This will deter from turning JS off and therefore any JS bits you have in your code will always work otherwise they cant access your site.

Any help is much appreciated.
Equinox Gaming Solutions Manager
http://www.equinoxgaming.co.uk

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Preventig Refresh
« Reply #21 on: October 12, 2007, 10:43:56 AM »
You could have a landing page which will redirect users to the game using javascript, so if somebody doesn't have javascript they will only see an error messages telling them to turn it on.

Or use the noscript tags to warn users.

These solutions probably won't guarantee that your users will turn on javascript but it could help :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal