Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

How to use PHP Include for Different Folders

General discussions related to php

Moderators: macek, egami, gesf

How to use PHP Include for Different Folders

Postby supermessiah » Sun Mar 23, 2014 5:03 am

I am having problems at the moment using a PHP include effectively.

The stylesheet named style.css, when accessed from the index.php file in the main directory works fine.
The problem is I try and access it from the buy and contact us pages. Because these files are in
folders, it means that the CSS link on the left is not relevant for those pages. Obviously if I change it to:
"../css/style.css", that would work for the buy and contact us pages but not the home page in the main directory.

Here is an example of the buy page (also relevant to the contact us page).

http://oi57.tinypic.com/2eauzbr.jpg

This is the PHP include I use on my home page index.php.

Image

And this is the PHP include I use on my buy and contact us pages.

Image

This allows the respective pages to link to the head.php, but obviously because the actual links in the head.php don’t change at the moment, it means it cannot work for the buy and contact us pages.

Using the example of the css/style.css line of code, how can I get it so this link is relative so it’ll work no matter where the page is housed? I don’t want to use absolute links because they’re a pain to change if need be.
supermessiah
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Dec 15, 2012 9:34 am

Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.