重定向标题

I have an email form, that i'm validating a date, its a booking form. What im doing is when the start date is bigger than the end date it gives me a message saying to fix the date and redirect to the page. I have 2 pages, the page of the booking form, and when i click to submit it goes to the contact_engine page to validate and send the email:

here is how i put it:

if ($datebegin >= $dateend){
    echo '<script>alert("Fix the Date");</script>'; 

exit;

The problem is when it does the exit it stays in the functions page, and i want it to exit but go to the previous page. Can someone give me some help? I tried instead using exit. I try to use it with header("Refresh: 1; url=http:/website.com/booking.php"); but somehow this takes me to the to the sent_page_booking page.

What about doing a timed redirect, so that the user gets the error message shown:

header("refresh:5;url=back-to-booking-form.php");
echo 'Form Error. Fix the date. Redirecting to the booking form in about 5 secs.'; 

I'd suggest an alternative approach: the correct way to handle form submission with validation is to use the Post-Redirect-Get technique:

  1. User submits the form (that is the POST request).
  2. Is the form valid? If so, process it and redirect to the confirmation page with GET.
  3. If the form isn't valid, just display the form with error messages (as a response to the original POST request.

To illustrate:

+--------+   POST   +--------+   Yes    +----------+   GET   +--------------+
| Submit | -------> | Valid? | -------> | Redirect | ------> | Confirmation |
+--------+          +--------+          +----------+         +--------------+
     ^                   |
     |                   | No
     +-------------------+

Use this:

header("Location: phppage.php");

and do not use echo before this code. Put this code in starting and call it with button event.

Use this Below link to exact answer

https://stackoverflow.com/questions/13539752/redirect-function

function redirect_url($path)
{
  header("location:".$path);
  exit;
}