How to handle user hitting the browser refresh

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Feller

    How to handle user hitting the browser refresh

    What are best practices to check to see if a .php script is called for the
    first time versus a user hitting a refresh button on their browser?

    I am playing around with a PHP front-end to a database. If the user enters
    values in a form (form.html), hits submit, the PHP script (insert.php) puts
    the submitted fields into the database as intended. insert.php displays a
    success message if successful or an error message otherwise. If the user
    hits the brower refresh button while at insert.php, the data is re-entered,
    and I end up with a duplicate entry in the database.

    This is the default behavior of Opera. IE prompts if I want to resend the
    data vs. not doing anything. If the data is resent, then the duplicate
    entry happens. I need to guard against this either way.

    Thanks for your help.



  • Chuck Anderson

    #2
    Re: How to handle user hitting the browser refresh

    Mark Feller wrote:
    [color=blue]
    >What are best practices to check to see if a .php script is called for the
    >first time versus a user hitting a refresh button on their browser?
    >
    >I am playing around with a PHP front-end to a database. If the user enters
    >values in a form (form.html), hits submit, the PHP script (insert.php) puts
    >the submitted fields into the database as intended. insert.php displays a
    >success message if successful or an error message otherwise. If the user
    >hits the brower refresh button while at insert.php, the data is re-entered,
    >and I end up with a duplicate entry in the database.
    >
    >This is the default behavior of Opera. IE prompts if I want to resend the
    >data vs. not doing anything. If the data is resent, then the duplicate
    >entry happens. I need to guard against this either way.
    >
    >Thanks for your help.
    >
    >
    >
    >
    >[/color]
    Ooh ooh, I know this one.

    Use the header function at the end of a successful insert to send the
    user to a different page (e.g., header("locatio n:
    insert_complete .php");). If they reload that, all it does is re-display
    the insert complete page - no duplicate entry.

    I handle errors in the same file (insert.php) with a form based back
    button to the form.html.

    --
    *************** **************
    Chuck Anderson • Boulder, CO

    Integrity is obvious.
    The lack of it is common.
    *************** **************

    Comment

    • Bob Smith

      #3
      Re: How to handle user hitting the browser refresh

      Mark Feller wrote:
      [color=blue]
      > What are best practices to check to see if a .php script is called for the
      > first time versus a user hitting a refresh button on their browser?
      >
      > I am playing around with a PHP front-end to a database. If the user
      > enters values in a form (form.html), hits submit, the PHP script
      > (insert.php) puts
      > the submitted fields into the database as intended. insert.php displays a
      > success message if successful or an error message otherwise. If the user
      > hits the brower refresh button while at insert.php, the data is
      > re-entered, and I end up with a duplicate entry in the database.
      >
      > This is the default behavior of Opera. IE prompts if I want to resend the
      > data vs. not doing anything. If the data is resent, then the duplicate
      > entry happens. I need to guard against this either way.
      >
      > Thanks for your help.[/color]
      as Chuck mentioned redirect the user after successful submission to the
      database. ( perhaps the db action should not be in a page delivered to the
      user, but a separate script, you can set the script to run in the action
      attribute of the form element )
      G
      --

      Comment

      • SOR

        #4
        Re: How to handle user hitting the browser refresh

        <comp.lang.ph p , Mark Feller , mjf77@lycos.com>
        <4LUBe.3730$Ih7 .773@newssvr33. news.prodigy.co m>
        <Fri, 15 Jul 2005 20:10:40 GMT>
        [color=blue]
        > If the user
        > hits the brower refresh button while at insert.php, the data is re-entered,
        > and I end up with a duplicate entry in the database.
        >
        > This is the default behavior of Opera. IE prompts if I want to resend the
        > data vs. not doing anything. If the data is resent, then the duplicate
        > entry happens. I need to guard against this either way.
        >[/color]

        I need to do the same thing .

        Was thinking of using the users ip address and a flatfile .

        - visit webpage
        - get the users ip address
        - get stored flatfile ip address
        - check and compare this ip address to the stored flatfile ip address

        - if same - exit
        - if different - save ip address to flatfile - proceed

        Havent tried it yet though - although in theory it shouldnt have any
        problems .

        Comment

        • SOR

          #5
          Re: How to handle user hitting the browser refresh

          <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
          <MPG.1d4355d399 c7c1a7989d16@no-cancel.newsread er.com>
          <Sat, 16 Jul 2005 18:41:12 +0100>
          [color=blue]
          > Was thinking of using the users ip address and a flatfile .
          >
          > - visit webpage
          > - get the users ip address
          > - get stored flatfile ip address
          > - check and compare this ip address to the stored flatfile ip address
          >
          > - if same - exit
          > - if different - save ip address to flatfile - proceed
          >
          > Havent tried it yet though
          >[/color]

          Seems to work fine on www.yellowvultures.co.uk having just tried it .

          Comment

          • Dana Cartwright

            #6
            Re: How to handle user hitting the browser refresh

            "SOR" <webmaster@spar esorrepair.co.u k.INVALID> wrote in message
            news:MPG.1d435e fb9c38f2f7989d1 7@no-cancel.newsread er.com...

            Was thinking of using the users ip address and a flatfile .[color=blue][color=green]
            >>
            >> - visit webpage
            >> - get the users ip address
            >> - get stored flatfile ip address
            >> - check and compare this ip address to the stored flatfile ip address
            >>
            >> - if same - exit
            >> - if different - save ip address to flatfile - proceed
            >>
            >> Havent tried it yet though
            >>[/color]
            >
            > Seems to work fine on www.yellowvultures.co.uk having just tried it .[/color]

            Be aware that visitors from AOL (just to cite one example) continually
            change their IP address (just hitting refresh will often change the IP).
            And there are many other mechanisms on the web that break the relationship
            between a person and their IP, as seen by your server. Search this group
            for many many discussions on this point.


            Comment

            • SOR

              #7
              Re: How to handle user hitting the browser refresh

              <comp.lang.ph p , Dana Cartwright , danapub2@weavem aker.com>
              <B8dCe.45180$0i 3.1483@twister. nyroc.rr.com>
              <Sat, 16 Jul 2005 19:23:13 GMT>
              [color=blue][color=green][color=darkred]
              > >> - visit webpage
              > >> - get the users ip address
              > >> - get stored flatfile ip address
              > >> - check and compare this ip address to the stored flatfile ip address
              > >>
              > >> - if same - exit
              > >> - if different - save ip address to flatfile - proceed
              > >>
              > >> Havent tried it yet though
              > >>[/color]
              > >
              > > Seems to work fine on www.yellowvultures.co.uk having just tried it .[/color]
              >
              > Be aware that visitors from AOL (just to cite one example) continually
              > change their IP address (just hitting refresh will often change the IP).
              > And there are many other mechanisms on the web that break the relationship
              > between a person and their IP, as seen by your server. Search this group
              > for many many discussions on this point.
              >[/color]

              Fair enough - but better than nothing I suppose .

              Comment

              Working...