Live Server Time Clock using PHP and Javascript………….

In this tutorial we are going to see how to set up PHP timestamp in javascript date object to simulate real time clock.
If we are going to make clock script only in php, for every second we need to make an ajax call to the server to get sever time to display on clicent side. It is completely bad scripting for making ajax call for every second to the server.
It good idea to assign php timestamp (server in time) to javascript variable, and run a javscript clock from that timestamp gives exact server time on the client side without making ajax call to the server.

 live server time clock script php javascript demo

Demo

 live server time clock script php javascript

Live Server Time Clock Using PHP Javascript

Step 1 :

Create index.php file. Now get php timestamp from php inbuilt DateTime class.

Now $current_timestamp will have current time in seconds from ( Jan 1, 1970). That’s it on PHP side.

 live server time clock script php javascript download

Download

Step 2:

Add <script> tag in index.php file.

Step 3:

where Javascript setInterval() method calls the phpJavascriptClock() function for every second to simulate real time clock.

flag variable helps to assign php timestamp to javscript timer variable only on page load.

But on subseqent function call ( phpJavascriptClock() ) value in the timer variable will incremented with 1000.

Here is the full Javascript clock script.

 

Posted by:

muni
  • http://www.smarttutorials.net muni

    .hide{display:none;}

    <?php while ( $result = mysqli_fetch_assoc($row) ) {
    if ( $i == 0) echo "”;?>

    <div id='question’ >
    <p class='questions' id="qname”> .
    <input type="radio" value="1" id='radio1_’ name=”/>

    <input type="radio" value="2" id='radio1_’ name=”/>

    <input type="radio" value="3" id='radio1_’ name=”/>

    <input type="radio" value="4" id='radio1_’ name=”/>

    <input type="radio" checked='checked' style='display:none' value="5" id='radio1_’ name=”/>

  • http://www.smarttutorials.net muni

    $i++;
    if ( ( $remainder < 1 ) || ( $i == $number_question && $remainder == 1 ) ) {
    echo "Finish”;
    echo “”;
    } elseif ( $rowcount > $number_question ) {
    if ( $j == 1 && $i == $number_question ) {
    echo “Next”;
    echo “”;
    $i = 0;
    $j++;
    } elseif ( $k == $rowcount ) {
    echo ” Previous
    Finish”;
    echo “”;
    $i = 0;
    $j++;
    } elseif ( $j > 1 && $i == $number_question ) {
    echo “Previous
    Next”;
    echo “”;
    $i = 0;
    $j++;
    }

    }
    $k++;

Related articles

My Favorite Blog

Quiz Web App

Responsive Quiz Application Using PHP, MySQL, jQuery, Ajax and Twitter Bootstrap

Be Happy!!!

Inspirational Quotes - Motivational Quotes- Short Stories

Does God Exists?

Inspirational Quotes - Motivational Quotes- Short Stories

Back to Top