简体   繁体   English

无法重定向到不同的网页

[英]unable to redirect to different webpage

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.我认为 header_remove() 将允许我发送一个新的 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 " $destination = " https://www.sustainablewestonma.org/swag/public/php/homeCtrl.php?place=Home "

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.希望你能找到解决办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM