Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
如何从url获取值并将其附加到url(php)中的现有值_Php_Url_Post_Url Rewriting_Append - Fatal编程技术网

如何从url获取值并将其附加到url(php)中的现有值

如何从url获取值并将其附加到url(php)中的现有值,php,url,post,url-rewriting,append,Php,Url,Post,Url Rewriting,Append,我的页面中有一个链接,看起来像这样:a href=?command=value,但当我单击该链接并重新加载页面时,它会首先加载另一个include php文件。基于cookie重定向用户的。如下所示:header('Location:?lang='。$redirect)因此当页面加载时?command=值消失 我需要在重定向包含文件中附加&command=value,因此url如下所示:?lang=en_US&command=value将重定向行更改为: header('Location: ?l

我的页面中有一个链接,看起来像这样:
a href=?command=value
,但当我单击该链接并重新加载页面时,它会首先加载另一个include php文件。基于cookie重定向用户的。如下所示:
header('Location:?lang='。$redirect)因此当页面加载时?command=值消失


我需要在重定向包含文件中附加
&command=value
,因此url如下所示:
?lang=en_US&command=value
将重定向行更改为:

header('Location: ?lang='.$redirect.'&command='.$_GET['command']);

您需要执行以下操作:

header('Location:?lang='.$redirect.&.$\u SERVER['QUERY\u STRING'])

以上内容将保留tack中关联的任何get数据。Codersarepople将只执行该命令

祝你好运

编辑:


一个潜在的缺点是,如果lang已经在查询字符串中,那么它也将被追加,因此要小心,这取决于使用情况。

我最喜欢http\u build\u查询函数:

$variables = $_GET;
$variables['lang'] = $redirect;
header('Location: ' . http_build_query($variables));

这样,您可以保留现有变量,添加自己的变量,并使用新的查询字符串进行重定向。

那么,为什么不能只执行
header('Location:?lang='.$redirect.&command=value')?位置标头必须包含完整的URL,包括“http://”和域名!它可能在没有浏览器的情况下工作,因为浏览器是宽容的,但它不应该这样,你也不应该指望它。+1写得很好。特别是它如何覆盖lang变量。