22/08: Using SERVER variables in PHP
Category: Development
Posted by: Editor
SERVER variables in PHP come in very handy when producing dynamic sites that may move from domain to domain. It is known that absolute links are more sturdy and search engine friendly than relative links.
Ok, theres a question: -
Q: Whats the difference between a relative link and an absolute link?
A: An absolute link will include the whole path to the object (http://www.seocrusade.com/marketing). Whereas a relative link will only include the necessary path info to the object (../marketing).
Right. So now we have established the difference between relative and absolute, the problem you may face is that by using absolute links, you will not be able to move your code between domains without changing the absolute links....
For example, you have a website hosted on www.domaina.com and want to move it to www.domainb.com, but all the link are written http://www.domaina.com in the code. Rather than doing a find and replace on all your domaina to domainb, write your code using $_SERVER['HTTP_HOST']!
for example http:.
Ok, so you may (should) be doing this anyway, but if you're not and your dynamic code is categorised by directory structure, then this is the answer.
Your code can then move from domaina to domainb without any code changes. This only works if your code is categorised by directory structure and not all within the one page.
Ok, theres a question: -
Q: Whats the difference between a relative link and an absolute link?
A: An absolute link will include the whole path to the object (http://www.seocrusade.com/marketing). Whereas a relative link will only include the necessary path info to the object (../marketing).
Right. So now we have established the difference between relative and absolute, the problem you may face is that by using absolute links, you will not be able to move your code between domains without changing the absolute links....
For example, you have a website hosted on www.domaina.com and want to move it to www.domainb.com, but all the link are written http://www.domaina.com in the code. Rather than doing a find and replace on all your domaina to domainb, write your code using $_SERVER['HTTP_HOST']!
for example http:.
Ok, so you may (should) be doing this anyway, but if you're not and your dynamic code is categorised by directory structure, then this is the answer.
Your code can then move from domaina to domainb without any code changes. This only works if your code is categorised by directory structure and not all within the one page.

