Reputation: 15685
Updated:
Is there a way to issue an alert and then redirect to another page? I tried the following but it doesn't work. I thought header_remove() would allow me to then send a new header.
<?php
require("../../includes/functions.php");
require("../../includes/newConstants.php");
$results = query("select * from users where email = ?",$_POST['email']);
if(count($results) == 0){
query ("insert into users (email,news)values(?,?)",$_POST['email'],true);
$values["msg"]="footer";
$body = file_get_contents('../../vhtml/email-footer.html');
$mailInputs = array("addAddress" => $_POST['email'],
"subject" => 'SWAG Mailing List Confirmation',
"body" => $body);
mailerExpressBlueHost($mailInputs);
echo '<script>alert("Please check your email for our Welcome message")</script>';
}else if(count($results) == 1){
echo '<script>alert("That email address is already here!")/script>';
header_remove();
redirect('https://www.sustainablewestonma.org/swag/public/php/homeCtrl.php?place=Home');
}else{
echo '<script>alert("FATAL ERROR:Please inform SWAG there\'s a proble"Welcome to Geeks for Geeks")</script>';
}
?>
function redirect($destination){
// handle URL
if (preg_match("/^https?:\/\//", $destination)){
echo "1 " .$destination;
header("Location:" . $destination);
}else if (preg_match("/^\//", $destination)){
// handle absolute path
$protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http";
$host = $_SERVER["HTTP_HOST"];
echo "2 " .$destination;
header("Location: $protocol://$host$destination");
}else if (preg_match("/^www/",$destination)){
$protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http";
echo "3 " .$destination;
header("Location: $protocol://$destination");
}else{
// handle relative path
// adapted from http://www.php.net/header
$protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http";
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
echo "4 " .$destination;
header("Location: $protocol://$host$path/$destination");
}
exit;
}
$destination = "https://www.sustainablewestonma.org/swag/public/php/homeCtrl.php?place=Home"
Upvotes: 0
Views: 50
Reputation: 333
To show an alert message and to redirect to another page, use the following:
else if(your_condition)
{
echo "<script type='text/javascript'>alert('Your message to display');
window.location='destination.php';
</script>";
}
This will work.
Hope you will find the solution.
Upvotes: 2