How can PHP be used to redirect to a URL without using the header function?

When we need to redirect to a different URL in PHP without using the header function, we can achieve this by using JavaScript. We can output a small script that will redirect the user to the desired URL using the window.location.replace() method.

echo '<script>window.location.replace("https://www.example.com");</script>';