PHP

PHP Code to Display Current Date & Time

Use the following code if you want to display Current Date and Time.

Simply copy the code in text file & save as .php file in the server. Change “Asia/Kuala_Lumpur” to your timezone.

<?php
   date_default_timezone_set('Asia/Kuala_Lumpur');
   $current_date = date('d-m-Y : H:i:s');
   echo $current_date;
?>

Auto Refresh Webpage with PHP, HTML and JavaScript

I’m developing server checking & monitoring webpage. I would left the page open all the time on my browser. So it will be good to that page auto refresh every certain amount of time so I don’t have to keep hitting F5 manually to refresh.

There are a few option that I have, I can do it either by using PHP Code, HTML Meta tag or JavaScript.

For example I want to refresh the webpage every 10 seconds. The are the code.

PHP Code

<?php
   $url=$_SERVER['REQUEST_URI'];
   header("Refresh: 10; URL=$url");
?>

 

HTML Meta Tag

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

 

JavaScript

<body onload=”javascript:setTimeout(“location.reload(true);”,10000);”>