How to redirect in PHP, using javascript in PHP.
TAGS: redirect, javascript, webpage, HTML, PHP


Javascript?
Yes!

I was looking for a way to redirect in PHP code to an URL, but I ended up using a small snip of javascript.
It looks like so:

?>
<script>location.assign("http://127.0.0.1/mypage.php");</script>
<?php


As you can see the page mypage.php is called by this snippet.
The little, but obvious trick is to use the close tag for the PHP code, then do the JS thing and then give the PHP start tag again, returning to the program.
Maybe not elegant, but it's working.