Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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 - Fatal编程技术网

使用PHP位置头

使用PHP位置头,php,Php,我试图在PHP位置头中使用一个变量,但似乎无法使其工作。我做错了什么? 我的代码: 仅凭假设。。是否要使用基于变量源的$\u GET值重新定向 那么: $id = 1; header("Location: collection.php?idollection=".$id); exit; 使用退出将确保调用标题后页面不会继续执行。此外,确保在调用标头之前没有空格或任何输出。确保使用双引号。您使用了单引号,实际上只使用了一个。试试这个: header("location:collection.p

我试图在PHP位置头中使用一个变量,但似乎无法使其工作。我做错了什么? 我的代码:


仅凭假设。。是否要使用基于变量源的
$\u GET
值重新定向

那么:

$id = 1;
header("Location: collection.php?idollection=".$id);
exit; 

使用
退出
将确保调用
标题
后页面不会继续执行。此外,确保在调用标头之前没有空格或任何输出。

确保使用双引号。您使用了单引号,实际上只使用了一个。试试这个:

header("location:collection.php?idcollection=$id");

了解变量插值变量不在单引号字符串中插值。字符串也应该用两个引号括起来。它不是“php位置标头”,而是http位置标头简化您的问题:
header()
函数使用字符串。您想创建一个内置值为
$id
的字符串。在上查找文档。
header("location:collection.php?idcollection=$id");