I want to display the URL of a page using PHP.

Basically do this:

<script language="javascript">
document.writeln(document.location);
</script>

with PHP

The problem is that I used a form with "get". So I need all that information in the URL. when I use that javascript tag, it displays the correct URL, but it I can't insert the javascript into 'href=' like I can with PHP.

ok then well theres two ways to do this then...

$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
echo $url;

this will always assume there is arguments in the address so u will always see a question mark int the address, a better way of doing this would be to test if there actually was any arguments before just adding the question mark such as in this example:

$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
	$url .= "?".$_SERVER['QUERY_STRING'];

echo $url;

i hope this answers any questions you do have

Thank you! It works wonderfully. Exactly what I wanted. May you live long and prosper.

Godspeed.

:eek:paradox814, you beet me tothe answer again. Good job m8!:p vbmenu_register("postmenu_82884", true);

hey i just rememberd one case in which this won't work!!!

if you are usign a secure ssl http session... in which case replace http:// with https:// (notice the s)

ok man, peace out

This article has been dead for over six months. Start a new discussion instead.