I want to redirect the user after five second this small snippet of codes redirects after 5 seconds.
<?php
ob_start();
echo "Thank you for your input";
header("Refresh: 5; url=http://www.google.com");
ob_end_flush();
?>
But When I try to implement it into my application nothing happens. here the header function doesn't work.
<?php
$name = "";
$email = "";
$subject = "";
$comments = "";
$nameError = "";
$emailError = "";
$subjectError = "";
$timestamp = date("Y-m-d H:i:s");
$x = 5;
$userIP = $_SERVER['REMOTE_ADDR'];
function filterData($data) {
$data = mysql_real_escape_string($data);
return $data;
}
$connection = mysql_connect('----', '----', '-----');
$select_database = mysql_select_db("contact");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//handles the name
$name = filterData($_POST["name"]);
if (empty($name)) {
$nameError = "please don't leave the name field blank";
}
//handles the email
$email = filterData($_POST["email"]);
if (empty($email)) {
$emailError = "please don't leave the email field blank";
}
//handles the subject
$subject = filterData($_POST["subject"]);
if (empty($subject)) {
$subjectError = "please don't leave this field blank";
}
$comments = filterData($_POST["comments"]);
}
$insertation = "INSERT INTO contactinfo (name, email, subject, date, comments, ip)
VALUES ('$name', '$email', '$subject', '$timestamp', '$comments', '$userIP')";
$insertationQuery = mysql_query($insertation, $connection);
ob_start();
echo "Thank you for your input";
header("Refresh: 5; url=http://www.google.com");
ob_end_flush();
?>
I have tried putting ob_start() and ob_end_flush() at the start and end respectively. But this still doesn't seem to work.