Redirect after submitting the form doesn't work
http-headers, php
Solution
Use javascript.
Instead of
header('location: http://www.google.com.au/');
Use,
?>
<script type="text/javascript">
window.location.href = 'http://www.google.com.au/';
</script>
<?php
It will redirect even if something is output on your browser.
But, one precaution is to be made: Javascript redirection will redirect your page even if there is something printed on the page.
Make sure that it does not skip any logic written in PHP.
Problem
This contact.php form was working to handle a submit and then redirect to a new page and then all of a sudden just stopped working. I have tried adding error handling and also moving header to the top in front of all other, but neither works. The form is still submitting the data as expected, it's just the redirect that doesn't work. Any ideas would be appreciated. ``` <?php include 'config.php'; $post = (!empty($_POST)) ? true : false; if($post) { $email = trim($_POST['email']); $subject = "Downloaded Course Units"; $error = ''; if(!$error) { $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: ".$email."\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail) { echo 'OK'; header('location: http://www.google.com.au/'); exit(); } } } ?> ```