What is the best way to achieve automatic page refresh in PHP?
To achieve automatic page refresh in PHP, you can use the header() function to send a refresh header to the browser. This header specifies the number of seconds after which the browser should automatically refresh the page. This is a simple and effective way to implement automatic page refresh in PHP.
<?php
// Set the refresh time in seconds
$refresh_time = 5;
// Send a refresh header to the browser
header("refresh: $refresh_time; url=yourpage.php");
?>
Keywords
Related Questions
- How can PHP developers ensure the correct Content-Type header is set when outputting JSON data to avoid rendering issues in browsers?
- How can PHP be used to write and read various data records to a file?
- What is the significance of the error message "Notice: Undefined index: short" in PHP code when accessing data from a database?