PHP 页面使用位置重定向:从 url 参数


PHP page redirects using location: from url parameter

我有一个重定向PHP页面,它检查URL参数并根据变量"shore"是否为1重定向到两个页面之一。但是,我的问题是,无论我做什么,页面都会重定向到第一个选项。谁能看到我缺少的任何明显的东西?

非常感谢

<?php
  require_once('Connections/ships.php');
if ($_GET['shore'] = "1") {
   header( 'Location: shore_establishment.php?ship_id=' .urlencode($_GET['ship_id']) . "?shore=1");
   //echo"first";
} else if ($_GET['shore'] = "0") {
    header( 'Location: shipinfo.php?ship_id=' .urlencode($_GET['ship_id']). "?shore=0");
   //echo"second";
};
?>

就像,@CommuSoft说,你在$_GET请求中的第二个?应该是一个&

你应该使用 == 而不是 = 来检查变量的内容

此外,我建议您使用 else 而不是 else if,因为只有两个选项(这更健壮,如果最终引入第三个变量,页面仍然会做一些事情)。