Results 1 to 7 of 7

Thread: Incorrect Time Displays When Back Button Is Used

  1. #1
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Incorrect Time Displays When Back Button Is Used

    1) Script Title: Local Time Script

    2) Script URL (on DD): http://dynamicdrive.com/dynamicindex6/localtime.htm

    3) Describe problem: I have recently been using the DD Local Time Script on my Web site with no problem. However, a couple of days ago, a visitor to my site told me that the clock was off by five minutes. I did not understand how that was possible since the Local Time Script gets the time from the server. After checking, I realized that whenever I navigated to another page and then clicked the back button, the clock would start up from where it left off when I last visited that page. It does not correct itself unless and until I click the refresh button.

    At first, I thought the problem was strictly with my Web site, but I checked another site that uses the Local Time Script, and the same thing occurred there. I even checked to see if it would happen at DD's Local Time Script page, and it did. When I clicked to another page, waited, and then clicked the back button, the time was off there, too.

    Is there any way to correct this problem? I don't want to assume that all visitors to my Web site will know that if they use the back button to navigate around the site, they will also have to click refresh if they want to see the correct time.

    -Thanks

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I think whenever you click on the back button of the browser window the time display page displays the page from the last state where you left it. It seems to me that the problem is regarding the browser cache.

    You can try to avoid this problem using the following meta tag by inserting this one in your time display page and check whether the problem exists or not

    Code:
    <meta http-equiv="cache-control" content="no-cache">
    Or if you are using PHP or any other server-side tool you can try to avoid the usage of cache using those tools directly.

  3. The Following User Says Thank You to codeexploiter For This Useful Post:

    R749er (04-02-2008)

  4. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    codeexploiter is right. Basically the problem isn't so much the script but the fact that browsers cache the contents of a page, including the current time generated by the server and added to the script. You'll have to choose one of the ways that's available to prevent page caching if this is really an issue for you.

  5. The Following User Says Thank You to ddadmin For This Useful Post:

    R749er (04-02-2008)

  6. #4
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    Or if you are using PHP or any other server-side tool you can try to avoid the usage of cache using those tools directly.
    Thanks, codeexploiter. I do use php on my Web site, but I am very new to it. Is there a php code that I should input in order to avoid the usage of cache so that my clock gives the correct time even when the back button is used?

    -Thanks

  7. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    It doesn't matter if your pages are PHP. You can still add the mentioned META tag to the top of your generated page source, inside the HEAD section:

    Code:
    <meta http-equiv="cache-control" content="no-cache" />

  8. The Following User Says Thank You to ddadmin For This Useful Post:

    R749er (04-03-2008)

  9. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Yes ddadmin is right you can achieve no cache using the <meta> tag like the way I've mentioned in my previous post.

    You can check the following URL in case of a PHP based solution and check the Example 2 in the page for more details

    http://in.php.net/header

  10. The Following User Says Thank You to codeexploiter For This Useful Post:

    R749er (04-03-2008)

  11. #7
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    You can check the following URL in case of a PHP based solution and check the Example 2 in the page for more details

    http://in.php.net/header
    Thanks for your help, ddadmin and codeexploiter. I tried the meta tag, but it didn't work for me. However, I did check out the URL you suggested, codeexploiter, and it led me to the following solution, which worked like a charm:

    <?php
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');
    ?>

    Thanks again you guys!

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
  •