Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Anti refresh in PHP

    I am looking for something to prevent people from refreshing a page or inside a function.

    Either by a pop up box saying refresh is disabled

    or

    By them being sent to another page stating refreshes are not allowed.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    if I were a user of your site, this would be the reason to never visit your site again.

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    It's not for the whole website, it's for a single page only. I don't want the content to be sent twice.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    what about if refferer is the same page dont send the content?

  • #5
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by masterofollies View Post
    It's not for the whole website, it's for a single page only. I don't want the content to be sent twice.
    Why? I think browsers cache stuff anyways to speed up the 2nd visit.




    ------------------
    Leonard Whistler

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    @seco, it's a POST submit, I need it accessed a few times over, but refreshing is a cheat. Because I am using RAND.

    @len once it's over and done with, they won't visit the page ever again
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #7
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    so is there content on this page they NEED to see?

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yeah, this is what it does. It's an attack mode.

    Enemy attacks you low. What do you want to do?
    If you select Defend Low you block it and damage the enemy for 1/4 health, if you select the wrong move, you are damaged for 1/4 health.

    There is a half dozen actions, confusing which one would be best for you. So if someone were to refresh the action, they could select the easiest one or the one they know is right multiple times.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #9
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    The only thing I can think of is to use COOKIES or a SESSION to keep score.



    -----------------
    Leonard Whistler

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    I am looking for something to prevent people from refreshing a page or inside a function.

    Either by a pop up box saying refresh is disabled

    or

    By them being sent to another page stating refreshes are not allowed.
    You can't control a users browser. You have to log and divert server side. That means using sessions, logging activity to the DB etc. You'll need to keep track of their actions on that page somehow and work from there.

  • #11
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    My website does use SESSIONS. You have to login to access anything other than the front page. So since I use SESSIONS. How can I do it?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    My website does use SESSIONS. You have to login to access anything other than the front page. So since I use SESSIONS. How can I do it?
    Set a session variable when they use that page and check for its existence each time the page is called. If it exists, then do whatever. You know they've been there. Header redirect, message etc.

  • #13
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Using sessions and mysql, it would be something like:

    User starts the game and the session id is entered into database, along with other info such as ip address. I would also give each game an easy to remember id number, such as game id 49276. Example of a session id.
    PHP Code:
    6a961341b0b7a08dbd7a2074289662f8 
    As the game is being played the score for game 49276 is updated only if the stored session id is equal to the current session id. Example:

    PHP Code:
    // does 6a961341b0b7a08dbd7a2074289662f8 == 6a961341b0b7a08dbd7a2074289662f8 
    if ($row[session_id] == $session_id) {

    // Play current game number 49276
    } else {
    // Start new game with new game number and session id generated. No more access to game 49276


    If the browser is exited then game over, since a new session id will be generated.



    -----------
    Leonard Whistler

  • #14
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    This is going to be confusing, let me try.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •