Automatically refresh the web page every 5 seconds, with PHP

Posted: March 5, 2011 in PHP
Tags: , , ,

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 ?>
About these ads
Comments
  1. arjun says:

    thank you for publishing my articles without any modifications and informing me,in exchange i appreciate if you provide back link to my blog http://www.bugphp.com

    awaiting for your response

  2. [...] Automatically refresh the web page every 5 seconds, with PHP [...]

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 )

Connecting to %s