to refresh a page?

Discussion in 'PHP' started by exentric, Feb 3, 2010.

  1. #1
    Hi..

    Is there any command to refresh a page?

    For example, I have a link in page1.php which takes me to page2.php. Again there is a link in page2.php which gets me back to page1.php.

    But every time when I am coming back to page1.php from page2.php, I want my page1.php to be refreshed to get the new data.

    As of now it wont get refreshed and I need to click the refresh button and its showing me the needed contents.

    Is there a way by which I could automatically refresh page1.php either after clicking on the link or before clicking on the link for page1.php?

    Thanks in advance.
     
    exentric, Feb 3, 2010 IP
  2. PJB

    PJB Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your browser is probably has probably cached the page - hence just shows it again without reloading.

    There's probably a more elegant solution than this... but you could just add a unique parameter to the url each time you redirect (even though nothing gets done with it).

    E.g.
    page2.php?unique_parameter=25467423
    page1.php?unique_parameter=99479797
    page2.php?unique_parameter=78748759

    - e.g. generate a random number each time, making the browser think that its a completely new page.
     
    PJB, Feb 3, 2010 IP
  3. exentric

    exentric Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    @PJB..

    That sounds good.. Thanks for the reply.. I will try it and get back with the result.
     
    exentric, Feb 3, 2010 IP
  4. gamepulse

    gamepulse Guest

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can try what PJB said, but... It is SEO unfriendly. However, a good solution ;) Just put a ?xyz=time() :D

    However, a data refresh can be done by using AJAX (or even more simple.. jQuery) or by a real refresh. Depending on your situation. "Real" refresh (like F5) can be done by adding a meta tag:
    <meta http-equiv="refresh" content="sec" />
    HTML:
    However, this is a timed refresh, which refreshes the page every sec seconds. Maybe you can combine it with iFrame or something :)

    Hope I helped you :D
     
    gamepulse, Feb 3, 2010 IP
  5. PJB

    PJB Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's a good point - if seo is important my suggestion isn't a good idea - I was thinking that it was an admin page or such like. Though you could use Google's canocial tag (google "Specify your canonical") to overcome this (but I'm not sure how many other search engines recognize this).
     
    PJB, Feb 3, 2010 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The "correct" way to do this is to tell the browser not to cache the page, by using the appropriate headers. Unfortunately browser support for this has varied over time, so you need a cocktail of headers to make it work reliably.
     
    SmallPotatoes, Feb 3, 2010 IP
  7. noname0

    noname0 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You may use this meta tag

    I have just copied it from Yahoo! Mail login page :)
     
    noname0, Feb 3, 2010 IP
  8. exentric

    exentric Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Heyy... Thanks everyone for all your help.. :)
     
    exentric, Feb 4, 2010 IP
  9. exentric

    exentric Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi.. I tried using all these commands. But I still have an issue related to this.

    For example, for the first time when I am going to page2.php from page1.php my page1.php is getting refreshed (I gave time() in the url). Again when I go from page1.php to page2.php. Now the next time when I am coming back to page1.php (by clicking the link), my page1.php is not getting refreshed..

    Could anyone please help me on this..
    (I apologize if my questions are sounding too stupid.. I am totally new to this.)

    Thanks..
     
    exentric, Feb 5, 2010 IP
  10. 0x00

    0x00 Well-Known Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    115
    #10
    Your browser probably cached the old page, try to ctrl+f5
     
    0x00, Feb 6, 2010 IP
  11. exentric

    exentric Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yes.. I am refreshing it manually now and it works.. But I want the page to get refreshed by itself.. Any other suggestion please?

    Thanks for your reply.. :)
     
    exentric, Feb 6, 2010 IP
  12. PJB

    PJB Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I'm out of ideas sorry!

    Have you tried using a different browser (firefox, chrom, ie)?

    Have you tried messing about with your browsers settings?

    E.g. in IE you can go into Tools->InternetOptions then BrowsingHistory Settings to tell it to always refresh).
     
    PJB, Feb 7, 2010 IP