SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting "Back Button" + force page refresh

    is there a way to detect if a user hit the back button? I want the page to force a refresh if the user hit the back button.

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If there is anyway to do this, you would have to use javascript not PHP. PHP cannot detect anything the user clicks in the interface.
    Wayne Luke
    ------------


  3. #3
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe not determining back/refresh, but definitely revisited... simply set a session variable... if it is NOT null, or something along those lines... then they would have been there already.
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  4. #4
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would i go about doing this? seems like i'd have to add a session variable for each part of the site.

    is there a better way to approach this problem?

    index.php
    PHP Code:
    require ('functions.inc.php');
    switch 
    $_GET['action']
    {
        case 
    'about':
            Function::
    has_visited('index''about');
            Function::
    did_visit('index','about');
            echo 
    'this is the about page';
            break;
     
        default:
            Function::
    has_visited('index','default');
            Function::
    did_visit('index','default');
            echo 
    'this is the homepage';

    functions.inc.php
    PHP Code:
    function has_visited($page$area)
    {
        if (
    $_SESSION['visited'][$page][$area]) 
        {
            unset(
    $_SESSION['visited'][$page][$area]);
            
    header('Location: ' $_SERVER['PHP_SELF'].'?'.SID.'&action='.$area);
        }
    }
    function 
    did_visit($page$area)
    {
        
    $_SESSION['visited'][$page][$area] = 1;

    essentially, what i want to do is to prevent the Warning: Page has Expired error when the user hits the back button.
    Last edited by GeekSupport; May 30, 2003 at 09:54.

  5. #5
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, off the top of my head... yah, you'd have to somehow store the pages visited in a session. This can be an array though, and therefore only 1 session variable (maybe just a big one though).

    Perhaps there is a simpler way, but I cannot think of one.
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just accept the fact the the user can press the BACK button if he/she so desires aye ?

    It's bad accessablity for the developer to interrupt the operations of the application, ie Web Browser.

    I've read HUNDREDS of Javascript forum posts of people wanting to disable the BACK button and it's pointless.

    Why stop the user from using the app as it's intended and so causing confusion for newbie's ?

  7. #7
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Just accept the fact the the user can press the BACK button if he/she so desires aye ?

    It's bad accessablity for the developer to interrupt the operations of the application, ie Web Browser.

    I've read HUNDREDS of Javascript forum posts of people wanting to disable the BACK button and it's pointless.

    Why stop the user from using the app as it's intended and so causing confusion for newbie's ?
    essentially, what i want to do is to prevent the Warning: Page has Expired error when the user hits the back button
    i think not preventing that page will cause more harm than good .
    A prime example of why it should be used is:

    1. user fills out a form which creates a new account
    2. confirmation page appears
    3. user clicks back button
    4. user tries to find newly created account in dropdown list.
    5. it won't be there if the script doesnt re-execute

    btw, i never said i wanted to prevent the user from clicking back. i wanted to prevent the error. they should be able to navagate anywhere they want. it our job, as developers, to make that experience as pleasureable (easy) as possible for the end user.

  8. #8
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess to a certain level it has to do with the coding itself... but say you made some post that added to a mysql database.. click back, and it executes that again... that isn't good!!!
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  9. #9
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KandieMan101
    I guess to a certain level it has to do with the coding itself... but say you made some post that added to a mysql database.. click back, and it executes that again... that isn't good!!!
    how isn't it good? i want the user to see the updated list, otherwise s/he will reenter the username and be presented with user already exists! or even worse, mis-type the name and now 2 accounts are created. now, "that isn't good!!!"

    btw, i took the example from how cpanel handles back buttons. as soon as i make a new database or database user and hit the back button, i don't need to refresh the page to get my database/user list updated. that's awesome!

    [edit]
    ahh, i see where you were going with that KandieMan101; i missread your post. the reload would only be in pages that don't process forms

    [edit2]
    hmm, i can't seem to reproduce cpanel reloading the pages anymore. i used to be able to hit the back button on my mouse (intelli explorer) and the page would auto-refresh.
    Last edited by GeekSupport; May 31, 2003 at 00:31.


Bookmarks

Posting Permissions

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