Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的页面没有成功重定向_Php - Fatal编程技术网

Php 为什么我的页面没有成功重定向

Php 为什么我的页面没有成功重定向,php,Php,我得到了一些代码;有一个$u POST变量(email)显示为包含内容,但当我使用isset测试它时,它失败了。我不明白为什么会失败;任何帮助都将不胜感激 这是PHP代码: <?php session_start(); echo "POST variables<br>"; var_dump($_POST); echo "<br><br>SESSION variables<br>"; var_dump($_SESSION); $ite

我得到了一些代码;有一个$u POST变量(email)显示为包含内容,但当我使用isset测试它时,它失败了。我不明白为什么会失败;任何帮助都将不胜感激

这是PHP代码:

<?php 
session_start();

echo "POST variables<br>";
var_dump($_POST);

echo "<br><br>SESSION variables<br>";
var_dump($_SESSION);


$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
if ($itemcount == 0)  {
header("Location: "."error.php?msg=".rawurlencode("Please add items to your shopping cart before checking out."));
exit;
} 

echo "POST email value: ".($_POST['email'])."<br>";

if (!isset($_POST['email']))  {  //  <--  FAILS HERE
header("Location: "."error.php?msg=".rawurlencode("We did not find your information, please enter the needed information again."));
exit;
} 

echo "server request method: ".$_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION['shipname'] = $_POST['shipname'];
$_SESSION['shipaddress'] = $_POST['shipaddress'];
$_SESSION['shipzip'] = $_POST['shipzip'];
$_SESSION['shipcity'] = $_POST['shipcity'];
$_SESSION['shipstate'] = $_POST['shipstate'];

$_SESSION['paymenttype'] = "PayPal";
header("Location: "."thankyou.php");
} 

$shipname = isset($_SESSION['shipname']) ? $_SESSION['shipname'] : '';
$shipaddress = isset($_SESSION['shipaddress']) ? $_SESSION['shipaddress'] : '';
$shipzip = isset($_SESSION['shipzip']) ? $_SESSION['shipzip'] : '';
$shipcity = isset($_SESSION['shipcity']) ? $_SESSION['shipcity'] : '';
$shipstate = isset($_SESSION['shipstate']) ? $_SESSION['shipstate'] : '';

?>
**更新:这是经过修订的代码,删除了所有“echo”语句:

<?php 
session_start();

$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
if ($itemcount == 0)  {
header("Location: error.php?msg=rawurlencode("Please add items to your shopping cart before checking out."));
exit;
} 

if (empty($_POST['email']))  {
header("Location: "."error.php?msg=".rawurlencode("We did not all of the required information."));
exit;
} 

else {
$_SESSION['shipname'] = $_POST['shipname'];
$_SESSION['shipaddress'] = $_POST['shipaddress'];
$_SESSION['shipzip'] = $_POST['shipzip'];
$_SESSION['shipcity'] = $_POST['shipcity'];
$_SESSION['shipstate'] = $_POST['shipstate'];

$_SESSION['paymenttype'] = "PayPal";


$shipname = isset($_SESSION['shipname']) ? $_SESSION['shipname'] : '';
$shipaddress = isset($_SESSION['shipaddress']) ?    $_SESSION['shipaddress'] : '';
$shipzip = isset($_SESSION['shipzip']) ? $_SESSION['shipzip'] : '';
$shipcity = isset($_SESSION['shipcity']) ? $_SESSION['shipcity'] : '';
$shipstate = isset($_SESSION['shipstate']) ? $_SESSION['shipstate'] : '';

header("Location: "."thankyou.php");
}
?>

取出
。这应该可以解决这个问题:如果你输入了一封有效的电子邮件,你就否定了true(它变成了false)

请记住,当您使用
isset()
时,它会返回一个布尔值(true或false)

请尝试:

if (empty($_POST['email']))  {  
header("Location: "."error.php?msg=".rawurlencode("We did not find your information, please enter the needed information again."));
exit;
} 

带有
头(“位置:…”)
的重定向不起作用的原因是,您已经通过回显发送了头


任何标题重定向之后都不会工作。

您没有定义“它失败”的含义。做什么失败?你试过这个
echo-isset($\u-POST['email'])吗set':'notset'
这也是毫无意义的
“Location:”.”error.php?msg=“
”,只是说我缺乏php的基本原理来这样做
“Location:error.php?msg=“
如果($\u SERVER['REQUEST\u METHOD']='POST')
你也可以去掉这个
如果($\u SERVER['REQUEST\u METHOD']='POST')
,然后在那里放一个else,因为显然如果
$\u POST['email']
i设置后,它必须是一个post请求。带有
标题(“位置:…”)
的重定向不起作用的原因是,您已经通过回显发送了标题。任何标题重定向都不起作用afterwards@Jeff-宾果!我会回答的。并将其添加到
ini\u集('display\u errors',1)位于页面顶部。这个问题措辞不好。它的措辞意味着页面正在重定向到错误页面。显然不是,因为我们看不到这个输出
服务器请求方法:
,我们显然看到了。一个更好的措辞是为什么我的页面没有重定向到成功。
if (empty($_POST['email']))  {  
header("Location: "."error.php?msg=".rawurlencode("We did not find your information, please enter the needed information again."));
exit;
}