Sessions

Discussion in 'PHP' started by MCJim, May 24, 2008.

  1. #1
    Is it possible to cancel a session if a user clicks 'refresh'? I don't want users to click refresh and resend data.

    Thanks in advance :) Sorry for the repost but I didn't realize there was a PHP sub-board; you can delete the original thread if you want.
     
    MCJim, May 24, 2008 IP
  2. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, and no...Using a captcha might work just right;) Because if the captcha doesn't match the session's data, it will void and you can from there say "session expired"

    But just normally doing it, no you really cant. I might be wrong, but as far as I know, you can't.
     
    NatalicWolf, May 24, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Redirect them using PHP's header("Location: wherever") after you parse the POST data so that if they do refresh, it refreshes that new page and doesn't try to resend the POST data. This is the best method I can think of other then setting a hidden input with a hash that is stored as a $_SESSION var and then deleted once they submit so if they refresh again, that hidden hash won't match up and it won't do anything. This would be the same as running a CAPTCHA only the person doesn't actually have to enter it.
     
    zerxer, May 24, 2008 IP
  4. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The problem is, I'm redirecting to the same page so I don't think the header method will work in this case.

    How can I do this? It sounds like it will work with a single page.
     
    MCJim, May 24, 2008 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    It works if you use header() to redirect to the very same page after submitting. Did you try? First try and then say anything about this.
     
    mwasif, May 24, 2008 IP
  6. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Unless I did it wrong, I got an error saying "The page isn't redirecting properly".
     
    MCJim, May 25, 2008 IP
  7. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can use sessions to prevent a refresh, yes:

    
    <?php
    session_start();
    if (empty($_SESSION['namehere'])) {
    	// let them do what they want here
    	$_SESSION['namehere'] = 'value';
                 session_write_close();
    } else {
    	// Hey, the session is written, so they must have already done this before!
    }
    ?>
    
    PHP:
    I hope this helps!
     
    itnashvilleCOM, May 25, 2008 IP
  8. MCJim

    MCJim Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    That helped -- I solved my problem. Thanks a lot!
     
    MCJim, May 25, 2008 IP
  9. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Anytime friend!
     
    itnashvilleCOM, May 25, 2008 IP
  10. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you want to allow the action again, call this:

     
    itnashvilleCOM, May 25, 2008 IP