在函数内PHP - header(“Location:”)重定向而不调用函数 [英] PHP - header("Location:") inside a function redirects without calling function

查看:104
本文介绍了在函数内PHP - header(“Location:”)重定向而不调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了正确重定向,我使用了一个名为 headerLocation()的函数。
这是函数的相关部分,我用它来重定向,然后显示一条适当的消息(个人喜好)。

I'm using a function called headerLocation() in order to redirect properly. This is the pertinent part of the function, I'm using it to redirect and then display an appropriate message (personal preference).

function headerLocation($location,$message)
{
    $_SESSION['output'] = $message;
    header("Location: ". $location);
}

问题是,当我运行脚本时, header(Location:。$ location); 部分在没有调用函数的情况下被激活(当我最初需要它用于php解析时)。
这使得该函数没用。

The problem is, when I run the script, the header("Location: ". $location); part is activated without even calling the function (when I initially require it for php parsing). This renders the function useless.

有没有办法解决这个问题?

Is there any way around this?

推荐答案

这不应该发生。要么你 在某处调用函数,要么代码的另一部分写出标题。你可以添加一些调试功能来检查?

That should not happen. Either you are calling the function somewhere, or another part of the code is writing out the header. Can you add some debug to that function to check?

这篇关于在函数内PHP - header(“Location:”)重定向而不调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆