Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 24, 2012, 12:03:19 PM

Pages: [1]   Go Down
  Print  
Author Topic: PHP 'include' file path question  (Read 531 times)
tech4all
Spaceship Captain
*****
Offline Offline

Posts: 119


« on: December 21, 2011, 04:50:25 PM »

First off let me say I'm no PHP expert, not even a beginner. I just know how to do that PHP include line in order to link to  receptive elements.

My question is I have my index.php page will includes the PHP include tag that links to other PHP files such a header and footer. Pretty simple. Based on the file paths in the header PHP, for example, the file paths (a graphic in this case) is in relevance to the main index.php file (or w/e file) and not the linked PHP file that shared across the site.

So since all pages in my site are inside a folder for their section, and the homepage isn't (it's in the root folder), that means I have to have separate PHP files; one for the homepage, and one for the pages that are inside folders because they have slightly different paths to the graphics folder. Index.php might go (graphics/image.gif) where the others would go (../graphics/image.gif). So I would need to two different PHP files where the only difference is the (../graphics) part.

Am I right?

Hope that makes sense!

Logged
lexhair
Galactic Royalty
*****
Offline Offline

Posts: 406


« Reply #1 on: December 22, 2011, 10:55:36 AM »

First off let me say I'm no PHP expert, not even a beginner. I just know how to do that PHP include line in order to link to  receptive elements.

My question is I have my index.php page will includes the PHP include tag that links to other PHP files such a header and footer. Pretty simple. Based on the file paths in the header PHP, for example, the file paths (a graphic in this case) is in relevance to the main index.php file (or w/e file) and not the linked PHP file that shared across the site.

So since all pages in my site are inside a folder for their section, and the homepage isn't (it's in the root folder), that means I have to have separate PHP files; one for the homepage, and one for the pages that are inside folders because they have slightly different paths to the graphics folder. Index.php might go (graphics/image.gif) where the others would go (../graphics/image.gif). So I would need to two different PHP files where the only difference is the (../graphics) part.

Am I right?

Hope that makes sense!


I recommend using full path file references in included files. Then it doesn't matter where the calling file is located on the server. If you have the graphics directory in your root, use "/graphics/image.gif".
« Last Edit: December 22, 2011, 10:57:40 AM by lexhair » Logged
Pages: [1]   Go Up
  Print  
 
Jump to: