Top.location.href Address of the top-level window This.location.href Address of the current window
#Test website: http://localhost/sangsir/manito.php?id=1 //Get domain name or host address echo $_SERVER['HTTP_HOST']; # localhost //Get web address echo $_SERVER['PHP_SELF']; #/ sangsir/manito.php //Get URL parameters echo $_SERVER["QUERY_STRING"]; # id=1 //Get the complete url echo 'http://'.$_ SERVER['HTTP_HOST'].$_ SERVER['REQUEST_URI']; // First echo 'http://'.$_ SERVER['HTTP_HOST'].$_ SERVER['PHP_SELF'].'?'.$_ SERVER['QUERY_STRING']; // Second # http://localhost/sangsir/manito.php?id=1 //Full url containing port number echo 'http://'.$_ SERVER['SERVER_NAME'].':'.$_ SERVER["SERVER_PORT"].$_ SERVER["REQUEST_URI"]; # http://localhost:80/sangsir/manito.php?id=1 //Take path only $url='http://'.$_ SERVER['SERVER_NAME'].$_ SERVER["REQUEST_URI"]; echo dirname($url); # http://localhost/sangsir