We know how to use Refresh Meta tags in our <head></head> tags. But what if we needed to do the same thing only this time do it in PHP?
We can use PHP's header() function
We can re-direct or refresh our web pages by simply doing either of the following in our PHP scripts or codes:Method I: using header('location...')
You probably know this ol' favourite...php:
<?php
// refresh / re-direct without delay
// ---------------------------------
header( 'location:http://www.desilva.biz/webdsn/' );
?>
Method II: using header('refresh...')
php:
<?php
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 5; url=/webdsn/' );
echo '<h1>You will be re-directed in 5 seconds...</h1>';
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 3; url=/' ); # redirects to our homepage
echo '<h1>You will be re-directed in 3 seconds...</h1>';
// refresh / redirect to an external web page
// ------------------------------------------
header( 'refresh: 0; url=http://www.example.net' );
echo '<h1>You won\'t know what hit you!</h1>';
?>
No comments:
Post a Comment