Hi,
This little man in the back of my head keeps telling me that I am not using PHP efficiently enough when trying to tell code where the location of things are. I will give you a few examples:
- For the start I created a variable to deal with the URL of the site like below:
$base_url = "http://www.mysite.com/";
unitl recently I have learned a different way which I will be implementing using the define CONSTANT method like below:
define('BASE', 'www.mysite.com');
The reason I want to use that is because I am putting together a function that will detect my server name like the example below:
$host = $_SERVER['SERVER_NAME'];
if($host == 'domain.com)
{
define('BASE', '$host');
}
else
{
define('BASE', '$host');
}
Firstly is the syntax correct above?
- Images - when I check out the source of my site the location of the images are displayed like so:
<img src="http://sitenorhost/images/home/image.png" title="random image" alt="random image" class="img">
but on other sites I have visited the display output is like this:
<img src="/img/graphics/navigation/noTab/ns-logo.png" alt="Network Solutions" border="0">
Why is this, what have I done wrong. Of course from a PHP point of view I want a robust dynamic solution to locate the necessary content. This also goes for links like below:
This is how I want it:
<li><a href="/main/mypage.php">Mypage</a></li>
but my ouput is like this:
<li><a href="http://www.mysite.com/main/mypage.php">Mypage</a></li>
this is because am using the variable
$base_url
. I believe it is not good to use the methods above and would like some sound detailed advice on how to make this work for me.
I am a leaner at PHP and I have got to this stage so far.
Thanks in advance