从HTTP_REFERER提取方案和主机 [英] Extract Scheme and Host from HTTP_REFERER
本文介绍了从HTTP_REFERER提取方案和主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有$_SERVER['HTTP_REFERER']
—假设它是 http://example.com/i/like/turtles.html .我该怎么做才能从字符串中仅获取http://example.com
部分,并将其存储在其自己的变量中?
I have $_SERVER['HTTP_REFERER']
— pretend it is http://example.com/i/like/turtles.html. What would I need to do to get just the http://example.com
part out of the string, and store it in its own variable?
推荐答案
In this example, the best solution would be to use PHP's parse_url
method. This splits up the URL into an associative array. You would then build your final value by combining the scheme
with the host
:
if ( $parts = parse_url( "http://example.com/i/like/turtles.html" ) ) {
echo $parts[ "scheme" ] . "://" . $parts[ "host" ];
}
这篇关于从HTTP_REFERER提取方案和主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文