无法重定向到其他网页

问题描述 投票:0回答:1

更新了。

有没有一种方法可以发出警报然后重定向到另一个页面? 我尝试了下面的方法,但不起作用。我想header_remove()可以让我发送一个新的头。

<?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.orgswagpublicphphomeCtrl.php?place=Home"

php redirect
1个回答
2
投票

要显示一个警告信息并重定向到另一个页面,使用下面的方法。

else if(your_condition)
        {
            echo "<script type='text/javascript'>alert('Your message to display');
                    window.location='destination.php';
                    </script>";
        }

这样就可以了

希望你能找到解决办法。

© www.soinside.com 2019 - 2024. All rights reserved.