Friday, 31 August 2018

PHP code does not run after calling a javascript alert

I'm having some troubles getting a php redirect to execute after a javascript alert is called. The code is below:

echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');

After clicking "OK" on the alert, the redirect does not execute. Any thoughts as to how I can get this code working?
Thanks

You can't send headers after your output. Just redirect the user thru javascript all the way instead.
echo '<script>window.location.href = "page.php";</script>';

0 comments:

Post a Comment