Skip to content
PHP Logo

How can PHP be used to handle output and redirection effectively?

To handle output and redirection effectively in PHP, you can use functions like ob_start() to buffer output, ob_get_clean() to retrieve and clear the buffer, and header() to perform redirection.

php
<?php
ob_start(); // Start output buffering

// Output content
echo "Hello, World!";

// Redirect to a new page after 3 seconds
header("refresh:3;url=redirected_page.php");

ob_end_flush(); // Flush the output buffer
?>