【问题标题】:header location in php not workingphp中的标头位置不起作用
【发布时间】:2015-01-20 09:26:13
【问题描述】:

我正在开发一个网站。我的代码有一个问题。请帮助我。 这是我的代码。在此标头位置不起作用。它在我的测试服务器上工作,但不在另一台服务器上工作。

请帮忙。

    <?php
    include("../config/config.php");
    include("../classes/db.class.php");
    include("../classes/functions.php");
    extract($_POST);
    $data=userLogin($vUsername,$vPassword);
    if($data!="")
    {
        if($data['eStatus']=='Inactive')
        {
            $_SESSION['error']='Your account is pending for approval.';
            header('Location:../login.php');
            exit;
        }
        else
        {
            foreach ($data as $key => $value) 
            {
                $_SESSION['userData'][$key]=$value;
            }
            deleteUnpaidOrder($_SESSION['userData']['iUserID']);
            clearCart($_SESSION['userData']['iUserID']);
            $_SESSION['success']='welcome '.$data['vFname'].' '.$data['vLname'].'!';
            if($data['iOrganizationTypeID']==3 || $data['iOrganizationTypeID']==2 || $data['iOrganizationTypeID']==5)
                header('Location:../location.php'); 
            if($data['iOrganizationTypeID']==1)
                header('Location:../exclusiveOpportunityForShopOwners.php');    
            if($data['iOrganizationTypeID']==4)
                header('Location:../manageInStoreAdvertising.php'); 
        }
    }
    else
    {
        $_SESSION['error']='Username or Password is wrong please try agian.';
        header('Location:../login.php');
    }
?>

【问题讨论】:

  • 定义“不工作”。实际发生了什么?如果您在浏览器的开发人员工具的“网络”选项卡中监视请求,您会看到什么?您看到对第一页的请求了吗?它得到回应了吗?响应是否包含位置标头?你看到第二页的请求了吗?它得到回应了吗?反应正确吗?服务器的日志文件说什么?如果您将 PHP 错误报告设置得尽可能高怎么办? (注意:虽然大多数浏览器会默默地纠正错误,但 Location 标头只接受 absolute URI,而不是相对的)。

标签: php redirect header location url-redirection


【解决方案1】:

@ob_start(); session_start();

在 config.php 文件的开头写上两行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 2016-08-21
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多