Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/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_Header - Fatal编程技术网

php头方法不使用';当位置来自函数时不起作用

php头方法不使用';当位置来自函数时不起作用,php,header,Php,Header,在我正在处理的页面上,它可以有密码保护,因此用户必须先登录才能看到内容。登录后,将调用以下代码: //In one file function current_page_url() { return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } //In Another file generate_page_cookie(); header('Location: ', current_page_url())

在我正在处理的页面上,它可以有密码保护,因此用户必须先登录才能看到内容。登录后,将调用以下代码:

//In one file
function current_page_url() {
    return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}

//In Another file
generate_page_cookie();
header('Location: ', current_page_url());
exit;
这不管用。然而,以下情况确实存在:

generate_page_cookie();
header('Location: ', 'http://example.com');
exit;
奇怪的是,在header函数中使用字符串可以工作,但在header函数中调用函数却不行


我认为这可能与访问$\u服务器变量有关,但我不确定。

更改为
,php使用
来压缩字符串

header('Location: ' . current_page_url());

哈,我检查了每个酒吧的打字错误。谢谢仅供参考:函数中缺少协议、端口和查询字符串。在头调用中使用输入之前,还应该验证输入。协议将始终是
http
current\u page\u url
函数尚未完成。我只是将其添加为注释,因为按字面理解您的问题标题可能会在此处找到完整的函数。没什么,是的。我只是想澄清一下。谢谢你的意见:)