tags:

views:

63

answers:

3

Hi friends,

I am working on a website in a CMS site. I have provided a link in my footer file e.g blogs.php. This page is at the root like "http://www.example.com/new_cms/blogs.php"

When I moves to other files link like "http://www.example.com/new_cms/forums" the footer link is changed to "http://www.example.com/new_cms/forums/blogs.php" but the blogs.php page resides at path "http://www.example.com/new_cms/" . I tried different $_SERVER[] variables but got no luck to get the above path "http://www.example.com/new_cms/" means the server name with the directory where the project is currently running from.

Any one have idea how to get it done will be a great help.

Thanks

+2  A: 

This is probably because your link has a relative url in it, like so :

<a href="blogs.php">Blogs</a>

So it looks for the blogs.php file in the current directory.

If you want that link to point to the blogs.php file that is in the new_cms folder, you have to use a link like this :

<a href="/new_cms/blogs.php">Blogs</a>
jfoucher
Thanks Friends for all of your help :) I think I have to use the static path of the directory inside my www root site directory.
kakaajee
A: 

You can obtain the server name from $_SERVER['SERVER_NAME'] that is the canonical server name specified in the server/virtual host configuration. Besides that $_SERVER['HTTP_HOST'] gives you the host specified in the HTTP request header field Host. In general, these two values are identical. But since both can be manipulated by user input (see Chris Shiflett’s SERVER_NAME Versus HTTP_HOST) you need to be careful when using these.

As for the path, you will probably need to specify the base URL path on our own. Because if you think of URL rewriting techniques, the physical path (file system path) does not need to be the same as the logical path (URL path). So you can not derive the logical base path from the requested URL path, the script file path and the document root.

Gumbo
A: 

You can use absolute URL or try to rewrite your url with a condition.

Brice Favre