Not long back I posted a thread at http://www.phpbuilder.com/board/showthread.php?t=10310698 entitled "Displaying the current URL/page". The basic problem I had was this: I used to use this PHP code to display the URL of the page that the visitor is currently viewing:
<? echo "$SERVER_NAME$PHP_SELF" ?>
When I changed my hosting company I noticed that this code no longer worked. But I found that this did work:
<? echo 'http://www.'.$HTTP_SERVER_VARS["SERVER_NAME"].$PHP_SELF.$_SERVER['REQUEST_URI']; ?>
Weedpacket however told me that the original code wouldn't work anymore because the new server had register_globals turned off, for security reasons, and that I should use:
$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].$_SERVER['REQUEST_URI']
...presumably like this:
<? echo 'http://www.'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].$_SERVER['REQUEST_URI']; ?>
But I find that this code returns URLs like this:
http://www.mydomain.co.uk/directory/index.php/directory/index.php
..it "adds on" an extra directory and page.
So I went back to using:
<? echo 'http://www.'.$HTTP_SERVER_VARS["SERVER_NAME"].$PHP_SELF.$_SERVER['REQUEST_URI']; ?>
Now this works fine, but because it was described as not "consistent", and because I'm just starting PHP, I'm still worried whether I'm using the right code!
Am I?