Question:

How to i get this PHP code to execute once every 10 seconds after the page has completely loaded?

by  |  earlier

0 LIKES UnLike

if (file_exists("pages/edit.html"))

{

$filepath_init = ("pages/edit.html");

$last_modified = filemtime($filepath_init);

//Last modified Monday, 27th October, 2003 @ 02:59pm

$variable1 = "Submitted: " . date("l, dS F, Y", $last_modified);

$checkvar2 = md5($variable1);

if $checkvar1 == $checkvar2

{echo("You are free to edit.");}

else

{

echo("STOP! Someone has just edited this, page, please reload.");

}

}

Im happy to use a JavaScript equivalent but prefer to stay with this code.

 Tags:

   Report

4 ANSWERS


  1. I dont know php coding but I have an idea.

    save this php code in a file. say, execute.php..

    if (file_exists("pages/edit.html"))

    {

    $filepath_init = ("pages/edit.html");

    $last_modified = filemtime($filepath_init);

    //Last modified Monday, 27th October, 2003 @ 02:59pm

    $variable1 = "Submitted: " . date("l, dS F, Y", $last_modified);

    $checkvar2 = md5($variable1);

    if $checkvar1 == $checkvar2

    {  (((redirect the user to the youarefree.htm)))   ;}

    else

    {

    (((redirect the user to the STOP.htm");

    }

    }

    now.. in the indicated htm files, put your message boxes.like this:

    <body onload="msgbox();">

    <script language="javascript">

    function msgbox(){

    alert("you are free to edit");

    }

    </script>

    do the same for other msgbox (stop!! someone. ..)

    now, when your main.html is loaded, put a timer in javascript, set its interval to 10000, and when the timer is triggered, call the execute.php in a hidden FRAME.


  2. You can't.  Php stays on the server and cannot INITIATE a download: it must be called by the "client" (the surfer).

    The only way is through javascript and AJAX.

    - client calls

    - Php replies with the page download

    - the download starts a javascript timer

    -> setTimeout ( js_function, delay)

    - js_function initiates an HTTPRequest that is processed by Php

    - Php sends the reply (reload or do nothing)

    To implement this, google "Sajax": you will get a free version of AJAX, especially designed for Php, and works like a dream.


  3. Impossible.

    The output buffer will only be sent to the browser (usually) one the PHP has all been parsed. Then the client disconnects from the server, because HTTP is stateless.

  4. Put this meta tag in the head of the file:

    <meta http-equiv="refresh" content="10" />

    That will refresh the page every 10 seconds.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.