Automatically refresh the web page every 5 seconds, with PHP

Redict the web page with PHP

you can easily redirect to the different web page using simple php script.By using PHP header() function you can easily redirect to new page without having new extra clicks.

the following PHP script redirect the user to bugphp.com

1 <?php
2 header( 'Location: http://www.bugphp.com/' ) ;
3 ?>

make sure,it will not work if you sent any data to the browser before this function.if you write echo or print or any HTML statements or functions before the redirection you will get an error,to avoid this use PHP output buffering as follows

1 <?php
2 ob_start();
3 echo 'header test';
4 header( 'Location: http://www.bugphp.com/' ) ;
5 ob_flush();
6 ?>

Automatically refresh the web page every 5 seconds, with PHP

1 <?php
2 $url=$_SERVER['REQUEST_URI'];
3 header("Refresh: 5; URL=\"" . $url . "\""); // redirect in 5 seconds
4 ?>
Advertisements

2 thoughts on “Automatically refresh the web page every 5 seconds, with PHP

  1. Pingback: PHP « amithmehta

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s