NZ_Kiwis;11050827 wrote:I have a page which is going to use a JS timer/interval.
My intervals could be long, 5-10 minutes even. What I want to prevent is a user refreshing the page to start that interval again. Using PHP how can I get around this? I have one option and want feedback on this and any other options.
Option 1:
Create a Interval of 15 seconds
Create a JS variable
Every 15 seconds send an AJAX call to update a PHP session on where I am in the count
Everytime my vairbale gets to a certan number it send another AJAX as my overall interval is up
Is running so many frequent AJAX/Interval calls an issue? is there a better way of going this?
Every 15 seconds is not too frequent at all in my experience -- although you should keep in mind that the shorter this interval is, the more requests your server will have to handle.
Preventing a user from refreshing a page is pretty much impossible. A user can always click 'refresh' in their browser and I would imagine that there's no good way to prevent the user from refreshing a page. I'm not entirely sure why you want to prevent them from "refreshing the page to start that interval again?" Perhaps you could clarify what situation you are trying to avoid more clearly? I would bet there is probably some way to structure things so that you need not worry about users refreshing their page -- you would track things on the server, using a database or sessions or some other logic perhaps?
Your post is a bit confusing to me about how you plan to handle these intervals--it suggests that you plan to create some JS variable and then loop to increase it or something. I would encourage you to look at the JS functions setTimeout and [/url=https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval]setInterval[/url].