PHP Paths


#1

I am using PHP inclusions for my websites (eg <?php require_once("/home/.maikki/myusername/domain.com/header.php");?>.

When I create sub-folders eg. domain.com/gallery, I used the same PHP paths for the files in that subdomain folder but they don’t seem to work.

Does this mean that I have to have the same header and footer file in each subfolder directory or is there a possible php path I could use to link the header from the main directory? :confused:


#2

Don’t do it like that, because the .maikki part may change. You should be able to use this anywhere:

<?php require_once($_SERVER['DOCUMENT_ROOT']."/header.php"); ?>I recommend putting all your includes in their own folder so that they are easier to keep track of. For example, I use this for a database connection:

<?php include($_SERVER['DOCUMENT_ROOT']."/includes/db.php"); ?>--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

Thanks scjessey! Okay hang on, so I use:

and I don’t need to replace anything? (except for the end php part). But do I still need to add a header and footer file in each of the subdomain files? :confused: because I’m testing the gallery/index.php and it doesn’t seem to work, without having to place a header and footer file.

Thanks for the tip on the folder bit :slight_smile:


#4

I don’t understand what your problem is. If you place that line of code on any page of your site (doesn’t matter what folder it is in), header.php will be included as expected.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#5

:stuck_out_tongue: Well that is the thing. I did put the code in files in subfolders but I get some error like I had the wrong paths :stuck_out_tongue:

Ah well, it’s okay - I just included a header + footer in each folder and it works :slight_smile:


#6

What error did you get? You shouldn’t be getting any errors with a simple include like that.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#7

It’s not really an error but it’s more of like, it doesn’t ‘connect’ with the header and footer in the main directory.

Now if I included a header and footer file in the gallery folder and add the gallery extension in the code, it works!

<?php require_once($_SERVER['DOCUMENT_ROOT']."/gallery/header.php"); ?>

:stuck_out_tongue:


#8

Ah I solved it lol!

Thread closed! :slight_smile: