Php 为什么我的本地主机无法重定向到其他页面?

Php 为什么我的本地主机无法重定向到其他页面?,php,html,Php,Html,我有以下php代码:我在signin.php <?php session_start(); if(!isset($_POST['firstName']) && !isset($_POST['lastName']) && !isset($_POST['email']) && !isset($_POST['password']) && !isset($_POST['confirmedPassword'])){ $_SES

我有以下php代码:我在signin.php

<?php
 session_start();
 if(!isset($_POST['firstName']) && !isset($_POST['lastName']) && !isset($_POST['email']) && 
 !isset($_POST['password']) && !isset($_POST['confirmedPassword'])){
 $_SESSION['error']="Please Fill Out all the fields";
 header("Location:signin.php");
    return;
}
else{
if($_POST['password']!=$_POST['confirmedPassword']){
    $_SESSION['error']="Passwords don't match.Retry!!";
    header("Location:signin.php");
    return;
    }else{
       header("Location:index.php");
    return;
    }
  }
 ?>

您正在重定向到登录页面。您可能会陷入一个无限循环,其中从不填充post变量(这是一个get请求)。因此,重定向次数过多,浏览器将启动并停止无限循环。

如果这五个
$\u POST[]
中的任何一个为空,则您将用户重定向到登录页面。当您执行
GET
请求
$\u POST[]
时,它自然会是空的,因此您会陷入无限循环。因此,在检查这些
$\u POST[]
变量是否存在之前,您只需检查请求类型

<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') //<--check request type
{
    if (empty($_POST['firstName']) || empty($_POST['lastName']) ||  empty($_POST['email']) || empty($_POST['password']) || empty($_POST['confirmedPassword']))
    {
        $_SESSION['error'] = "Please Fill Out all the fields";
        header("Location:signin.php");
    }
    else
    {
        if ($_POST['password'] != $_POST['confirmedPassword'])
        {
            $_SESSION['error'] = "Passwords don't match.Retry!!";
            header("Location:signin.php");
        }
        else
        {
            header("Location:index.php");
        }
    }
}
exit;
?>

即使在我删除了整个else部分后也不起作用。您还有一个if部分,用于检查第3行上的post变量。这个PHP页面位于什么位置?我在signin.phpWell,似乎Hackinet为您做了繁重的工作是
index.PHP
signin.PHP
中的上述代码?如果是,您的If条件存在一些问题。我在signin.phpany退出和返回之间的差异?@编码员我更新了答案以使用
|
代替
&&
。另请阅读:。在这个场景中几乎是一样的,但是从全局的角度来看,
exit
更好,并且正是针对这种情况而设计的。
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') //<--check request type
{
    if (empty($_POST['firstName']) || empty($_POST['lastName']) ||  empty($_POST['email']) || empty($_POST['password']) || empty($_POST['confirmedPassword']))
    {
        $_SESSION['error'] = "Please Fill Out all the fields";
        header("Location:signin.php");
    }
    else
    {
        if ($_POST['password'] != $_POST['confirmedPassword'])
        {
            $_SESSION['error'] = "Passwords don't match.Retry!!";
            header("Location:signin.php");
        }
        else
        {
            header("Location:index.php");
        }
    }
}
exit;
?>