PHP将变量附加到地址栏中的url
我想知道当页面加载时,是否可以在地址栏的url中附加一个变量 演示: 当前页面位于地理位置,如果category=Central Austin…希望url加载为PHP将变量附加到地址栏中的url,php,variables,url,append,Php,Variables,Url,Append,我想知道当页面加载时,是否可以在地址栏的url中附加一个变量 演示: 当前页面位于地理位置,如果category=Central Austin…希望url加载为 =奥斯汀市中心 =奥斯汀市中心 有什么建议吗?尝试使用重定向,例如 您可能应该使用JavaScript,这里有两个选项: 重新定向 // similar behavior as an HTTP redirect window.location.replace("http://communityimpact.com/discussio
=奥斯汀市中心
=奥斯汀市中心
有什么建议吗?尝试使用重定向,例如
您可能应该使用JavaScript,这里有两个选项:
- 重新定向
// similar behavior as an HTTP redirect window.location.replace("http://communityimpact.com/discussions/central-austin"); // similar behavior as clicking on a link window.location.href = "http://communityimpact.com/discussions/central-austin";
$my_category = "Central Austin";
$my_category_grub = "central-austin";
header("location: community-impact/discussions/$my_category_grub");
//or append a var like this:
header(" location: community-impact/discussions/?location=$my_category_grub");
//then you could handle the request on the new page
但这两种方法都会重定向您
如果您想使用$\u会话变量将更有意义。我看不到在URL中添加变量而不重定向的任何可能性。Url是地址,如果更改Url,则必须更改页面。但是会话变量会一直存在,直到它们离开您的站点。我不知道你的目的是什么
$_SESSION["category"] = "central-austin";
但你必须
session_start();
在页面的开头。这实际上并没有附加URL-它会强制浏览器进入另一个页面。@HPierce…其中包含值,因此效果很好^^^需要在这两个变量的值周围加上一个分号:)是的,哈哈。对不起,我打错了。修理。
$_SESSION["category"] = "central-austin";
session_start();