Hello.

I have a page that needs to refresh one part every time the page is visited. This part is controlled by
include "refreshme.php";

However, the data only refreshes when the browser's refresh button is physically pressed. I have included the following headers at the top of the source page.

header("Expires: Thu, 1 Sep 2007 07:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header("Pragma: no-cache");

Still no luck. Any idea on how to do this? I accomplish image refreshing by attaching a random number to the file. Example:

<?php $rand=rand(100000,999999); $rand="?".$rand;?>
<img src="<?php echo $picture.$rand;?>">

I cannot get something similar to work on the included php file.
Any help would be great. Thanks.

    PHPsites wrote:

    Hello.

    I have a page that needs to refresh one part every time the page is visited. This part is controlled by
    include "refreshme.php";

    However, the data only refreshes when the browser's refresh button is physically pressed. I have included the following headers at the top of the source page.

    header("Expires: Thu, 1 Sep 2007 07:00:00 GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header("Pragma: no-cache");

    Still no luck. Any idea on how to do this? I accomplish image refreshing by attaching a random number to the file. Example:

    <?php $rand=rand(100000,999999); $rand="?".$rand;?>
    <img src="<?php echo $picture.$rand;?>">

    I cannot get something similar to work on the included php file.
    Any help would be great. Thanks.

    You could use some AJAX, here is how i would do it

    1- in you head tag include this

    <script type="text/javascript">
    var page = "refreshme.php";
    function ajax(url,target)
     {
        // native XMLHttpRequest object
       document.getElementById(target).innerHTML = '<font color="white">0</font> some text here if needed';
       if (window.XMLHttpRequest) {
           req = new XMLHttpRequest();
           req.onreadystatechange = function() {ajaxDone(target);};
           req.open("GET", url, true);
           req.send(null);
       // IE/Windows ActiveX version
       } else if (window.ActiveXObject) {
           req = new ActiveXObject("Microsoft.XMLHTTP");
           if (req) {
               req.onreadystatechange = function() {ajaxDone(target);};
               req.open("GET", url, true);
               req.send();
           }
       }
    		   setTimeout("ajax(page,'scriptoutput')", 10000); // the refresh time 
    }
    
    function ajaxDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200 || req.status == 304) {
    results = req.responseText;
    document.getElementById(target).innerHTML = results;
    } else {
    document.getElementById(target).innerHTML="ajax error:\n" +
    req.statusText;
    }
    }
    }
    </script>

    2- on your body tag call the function onload

    ajax(page,'scriptoutput');

    3- then include this div where you want the information displayed

    <div class="regular" align="left"><span id="scriptoutput"></span></div>

    This might need some changes to customize to your likes but it's a start.

    im sure there are more ways to do this but this is one way, to refresh without actually refreshing the whole page.

    Cheers.

      Thanks for the response. Is anyone aware of a way to do this only with PHP? For this project I would like to avoid Javascript, if possible.

        Write a Reply...