Coding the full path as a variable
Posted: Sun Aug 08, 2010 8:41 am
I assume this must be trivial for the PHP experts, but since I'm not one of them...
On my Apache/PHP website, the links to other pages on the site are coded as relative paths, e.g. 'main/page01.php'. However, for various reasons, I would like to code some of them as full paths, e.g. 'http://www.mysite.com/main/page01.php'.
Now, I am developing and testing this website on a PC where the corresponding address is something like 'http://localhost:8080/mysite/test/main/page01.php'. So, in order to allow local testing, I do not want to code full server-side paths. Instead, I would like to use a variable that, according to the context (local PC or server), delivers the correct path.
I thought that some coding with $_SERVER would allow me to do so, but it seems more complex than that. So, is there anyone who knows how to code this or who has some other suggestion for doing this?
On my Apache/PHP website, the links to other pages on the site are coded as relative paths, e.g. 'main/page01.php'. However, for various reasons, I would like to code some of them as full paths, e.g. 'http://www.mysite.com/main/page01.php'.
Now, I am developing and testing this website on a PC where the corresponding address is something like 'http://localhost:8080/mysite/test/main/page01.php'. So, in order to allow local testing, I do not want to code full server-side paths. Instead, I would like to use a variable that, according to the context (local PC or server), delivers the correct path.
I thought that some coding with $_SERVER would allow me to do so, but it seems more complex than that. So, is there anyone who knows how to code this or who has some other suggestion for doing this?