Get what page the visitor visit in PHP
<p>I was trying to get what page the visitor visit:</p>

<p>Here is my code: </p>

<pre><code>$url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$urlcomplete = $url;
$url = explode(".com/",$url);
$urlcount = count($url);
$newurl = '';
for ($start = 1; $start &lt; $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);
</code></pre>

<p>By using the code above, all the subpage will be store in the $url.</p>

<p><a href="http://stackoverflow.com/questions/ask">http://stackoverflow.com/questions/ask</a></p>

<pre><code>$url[0] = 'questions'
$url[1] = 'ask'
</code></pre>

<p>Just want to ask, is this good way, or there are others better way?</p>
