0

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

0

4 Answers 4

2

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>';
Sign up to request clarification or add additional context in comments.

Comments

0

You can't output anything before calling header, not even a single space. You can use header before outputting the script like in the code below

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

Hope this helps you

Comments

0

This is the best you can do use :-

window.location

http://www.w3schools.com/js/js_window_location.asp

Comments

0

try this way

echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.