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

gan*_*jan 0 php url post append url-rewriting

我的页面中有一个链接看起来像这样:a href=?command=value但是当我点击链接并重新加载页面时,首先加载另一个包含php文件.根据cookie重定向用户.像这样:header('Location: ?lang='.$redirect);所以当页面加载时,'command = value就消失了.

我需要&command=value在重定向包含文件中追加,所以url看起来像这样:?lang=en_US&command=value

Bli*_*izz 7

我最喜欢http_build_query函数:

$variables = $_GET;
$variables['lang'] = $redirect;
header('Location: ' . http_build_query($variables));
Run Code Online (Sandbox Code Playgroud)

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