Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - auto refreshing page

Tags:

php

I am using following code for a refreshing page, it is not reloading on completion. The following code is not working sometime.

 $page = $_SERVER['PHP_SELF'];  $sec = "10";  header("Refresh: $sec; url=$page");  echo "Watch the page reload itself in 10 second!"; 
like image 580
Fou Avatar asked Jul 16 '12 02:07

Fou


People also ask

Can I refresh a page from PHP?

PHP is server-side language, so you can not refresh the page with PHP, but JavaScript is the best option to refresh the page: location. reload();

How do I refresh HTML automatically?

Approach 1: One can auto refresh the webpage using the meta tag within the head element of your HTML using the http-equiv property. It is an inbuilt property with HTML 5. One can further add the time period of the refresh using the content attribute within the Meta tag.

How reload the current page without losing any form data in PHP?

The easiest way to reload the current page without losing form data, use WebStorage where you have -persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed. window. onload = function() { var name = localStorage.


2 Answers

Use a <meta> redirect instead of a header redirect, like so:

<?php $page = $_SERVER['PHP_SELF']; $sec = "10"; ?> <html>     <head>     <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">     </head>     <body>     <?php         echo "Watch the page reload itself in 10 second!";     ?>     </body> </html> 
like image 84
nickb Avatar answered Oct 08 '22 14:10

nickb


you can use

<meta http-equiv="refresh" content="10" >  

just add it between the head tags

where 10 is the time your page will refresh itself

like image 24
Ram Aquino Avatar answered Oct 08 '22 13:10

Ram Aquino