How can JavaScript or meta tags be used for page redirection in PHP as an alternative to the header() function?

When the header() function cannot be used for page redirection in PHP due to output already being sent to the browser, JavaScript or meta tags can be used as alternatives. JavaScript can be used to redirect the page using window.location.href, while meta tags can be placed in the HTML <head> section to automatically redirect the page after a specified time.

// Using JavaScript for page redirection
echo &#039;&lt;script&gt;window.location.href = &quot;newpage.php&quot;;&lt;/script&gt;&#039;;

// Using meta tags for automatic redirection after 5 seconds
echo &#039;&lt;meta http-equiv=&quot;refresh&quot; content=&quot;5;url=newpage.php&quot;&gt;&#039;;