使用PHP,我想返回当前页面的当前网址。PHP:返回当前URL
例如,如果这个脚本在运行http://www.google.com,我想呼应出“谷歌” SANS的http://
OR
如果这个脚本在运行http://173.244.195.179,我想呼应出'173.244.195.179'sans http://
我已经看过$_SERVER
,但一直未能得到它的工作。建议?
使用PHP,我想返回当前页面的当前网址。PHP:返回当前URL
例如,如果这个脚本在运行http://www.google.com,我想呼应出“谷歌” SANS的http://
OR
如果这个脚本在运行http://173.244.195.179,我想呼应出'173.244.195.179'sans http://
我已经看过$_SERVER
,但一直未能得到它的工作。建议?
$domain = $_SERVER['HTTP_HOST'];
$ar = explode('.', $domain);
echo $ar[0];
也许吧?
编辑:(支持子域)
function domain()
{
$ends = array('net','com','info','org');
$domain = $_SERVER['HTTP_HOST'];
$ar = explode('.', $domain);
$result = '';
$i = 0;
$found = false;
for($i; $i<sizeof($ar); $i++)
{
$j = 0;
for($j; $j<sizeof($ends); $j++)
{
if($ends[$j] == $ar[$i]) $found = true;
}
if($found) break;
$result .= $ar[$i] . '.';
}
return substr($result, 0, strlen($result)-1);
}
echo domain();
我要去把我的钱是有这样做的方式更简单或内置方式。
你想回应'谷歌'或'www.google.com'? – 2011-05-04 07:51:27
[获取当前URL]的可能重复(http://stackoverflow.com/questions/5216172/getting-current-url) – 2011-05-04 07:54:19
只是谷歌注意到其他 – dukevin 2011-05-04 07:54:55