Friday 4 March 2011

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










2header( '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










2ob_start();










3echo 'header test';










4header( 'Location: http://www.bugphp.com/' ) ;










5ob_flush();










6?>




Automatically refresh the web page every 5 seconds, with PHP









1<?php










2$url=$_SERVER['REQUEST_URI'];










3header("Refresh: 5; URL=\"" . $url . "\""); // redirect in 5 seconds









4?>

No comments:

Post a Comment