我试图获取访问者访问的页面:
这是我的代码:
$url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$urlcomplete = $url;
$url = explode(".com/",$url);
$urlcount = count($url);
$newurl = '';
for ($start = 1; $start < $urlcount; $start++) {
if ($newurl != '') {
$newurl .= '.com/';
}
$newurl .= $url[$start];
}
$url = explode('/',$newurl);
$urlcount = explode('?',end($url));
$url[count($url) - 1] = $urlcount[0];
$urlcount = count($url);
通过使用上面的代码,所有子页面都将存储在 $url 中。
https://stackoverflow.com/questions/ask
$url[0] = 'questions'
$url[1] = 'ask'
只是想问一下,这是好方法,还是有其他更好的方法?