I want to use the query that someone used to find my page, these are in the URL of the referring page $GET_['q'] (and for yahoo $GET_['p']). How can I use these? I want something like $query = REFERRING PAGE ($GET_['q']), but I just can't figure out the way to say it.
1条回答 默认 最新
- drze7794 2009-09-22 21:32关注
The information you are searching for is available in
$_SERVER['HTTP_REFERER']
For instance, coming from a page with this URL :
http://tests/temp/temp-2.php?q=test+glop
, this portion of code :var_dump($_SERVER['HTTP_REFERER']);
Gives :
string 'http://tests/temp/temp-2.php?q=test+glop' (length=40)
You can the useparse_url
to get the query string from that URL :$query = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY); var_dump($query);
will get you :
string 'q=test+glop' (length=11)
Now, you can parse that query string withparse_str
; this code :$params = array(); parse_str($query, $params); var_dump($params);
Will get you :
array 'q' => string 'test glop' (length=9)
And, finally, you can check whether the parameter that interests you is in that array :if (isset($params['q'])) { var_dump($params['q']); }
Will give us, in this example :
string 'test glop' (length=9)
Et voila ;-)Just note that the Referer is sent by the client, which means :
- it can be forged, and can contain anything -- including bad stuff (beware SQL injections and XSS !)
- it is optionnal : the browser is not required to send it.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 wegame打不开英雄联盟
- ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
- ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
- ¥30 eclipse开启服务后,网页无法打开
- ¥30 雷达辐射源信号参考模型
- ¥15 html+css+js如何实现这样子的效果?
- ¥15 STM32单片机自主设计
- ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
- ¥15 不小心不正规的开发公司导致不给我们y码,
- ¥15 我的代码无法在vc++中运行呀,错误很多