【问题标题】:Redirect function is not working on the live server. But working on localhost重定向功能在实时服务器上不起作用。但是在本地主机上工作
【发布时间】:2012-06-24 08:27:07
【问题描述】:

这就是函数。这是在本地主机上工作的。但不能在实时服务器中工作。

function redirect_to($location = NULL){
    if($location != NULL){
        header("Location: {$location}");
        exit;
    } 
}

if(mysql_affected_rows() == 1){
    //success

    redirect_to("index.php");
}

【问题讨论】:

  • redirect_to($location = NULL),你为什么要给它赋值null?!
  • 它给出,因为最初它是空的。那是错的吗?但这是在本地主机上工作
  • 如果在实时服务器上调用脚本会发生什么?你看到一个空白页吗?是否调用了redirect_to?也许 $location 参数为空?
  • 返回的http状态是什么?你得到位置标题吗?你检查你的错误日志了吗?
  • @Maerlyn : retun http status 是什么意思???你能再澄清一下吗?

标签: php


【解决方案1】:

不要为参数定义默认值然后检查它,只是不要一开始就给它一个默认值。同时删除 Location: 标头中的括号。

function redirect_to($location){
    header("Location: $location");
    exit;
}

if(mysql_affected_rows() == 1){
    //success

    redirect_to("index.php");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多