SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Refresh and PHP

    Hi,

    I know I saw some similar posts to this but, nothing exactly with what I am looking for. What I need to do is refresh a page once every time a user comes to a page within the site. Now, this script needs to be placed within the main template script that is included in all site's scripts. How do I do a single refresh of the page and NOT have the page loop with its refreshing? Basically, how do I know the page has refreshed? The reason for this is to simply flush any client side caching of the page.

    Thanks,

    Brett
    Last edited by goughb; Jul 3, 2002 at 07:53.

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The appropriate way to do this would be to set cache control mechanisms on the page, rather than trying to outsmart the javascript refresh loop.

    What server-side language are you using? (PHP, ASP, etc) or is it all straight HTML?

  3. #3
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP

  4. #4
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    header
    ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modifieed: "gmdate("D, d M Y H:i:s"). " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Cache-Control: post-check=0,pre-check=0");
    header("Cache-Control: max-age=0");
    header("Pragma: no-cache");
    ?>
    should just about cover it. :-)

  5. #5
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You!

    -Brett

  6. #6
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about if the user hits the back button, it doesn't refresh?

    -Brett

  7. #7
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind..your code should look like this:

    PHP Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modifieed: "gmdate("D, d M Y H:i:s"). "GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Cache-Control: post-check=0,pre-check=0"false);
    header("Cache-Control: max-age=0"false);
    header("Pragma: no-cache"); 
    int header ( string string [, bool replace])

    The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type. For example:
    Without the false paramater when the header read "Cache-Control again.. it would replace the previous header as opposed to adding it on. I think..

    -Brett


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
  •