Refresh page using PHP


Refresh page using PHP Function : Sometimes in php we need to reaload ie. refresh a page. There can be several ways to refresh a page in php we are going to explain few of them. In this tutorial we will explain how you can refresh a page after some interval of time.


Refresh page using PHP

You can use the header() function to refresh the page here is an example to refresh the page using this function-

Refresh page using PHP function:

$second = 10;
header("Refresh:$second");

This will refresh page after each 10 seconds.

Refresh page using PHP And Redirect to another page-

If you to redirect to another page after refreshing the page you can add the second parameter ie. page you want to redirect-

Refresh page using PHP And Redirect to another page-:

$second = 10;
header("Refresh:$second; url=testpage.php" );

This will refresh the page after the given time and redirect to the given page.

More About PHP Refresh Page

Let us have look over another methods which we can use to refresh the page in php.

Refresh page in PHP using HTML META

You can also refresh a page using the HTML META as below-

Refresh page in PHP using HTML META Example

echo("<meta http-equiv='refresh' content='1'>");

Refresh page in PHP using Javascript

You can also refresh a page using the javascript as below-

Refresh page in PHP using Javascript Example

<?php
// your php code
?>
<script type="text/javascript">
location.reload();
</script>
<?php
// your php code
?>

You can also use the javascript to refresh the page in php. The above example will reload the same page after refreshing.


Advertisements

Add Comment

📖 Read More