Hi there,
First off, i'm total newby at php. I know basic functions such as <?php include and thats about it really!!!
My pages are set up the following way...
1. I have a /common folder which has the header.php and footer.php and any other 'common' pages I need.
2. I then have my index.php file which calls the header and the footer.php from the /common folder.
3. I've also created a new folder (/newfolder) which has a file in /newfile.php so from the root its - newfolder/newfile.php
4. I also have an images folder which the files are linked to from each page I create.
My problem is that this changes from page to page as they are in different directories and different levels.
Is there a best way to do this so I don't have to use ../folder/file.php? I've tried /folder/file.php but I get the following error - Warning: include(/common/header.php) [function.include]: failed to open stream: No such file or directory in /homepages/27/d194522123/htdocs/webfeetdesign/testing/lwk-tests/white-layout/landing.php on line 12
To see the mess i've created go to http://xxxxxxxxxxx.com
Hope someone out there can understand my gibberish!!!
Many thanks
Alex
How do I make my website pages location independent?
Moderator: General Moderators
-
webfeetdesign
- Forum Newbie
- Posts: 3
- Joined: Tue Aug 16, 2011 11:17 am
How do I make my website pages location independent?
Last edited by califdon on Tue Mar 06, 2012 12:28 pm, edited 1 time in total.
Reason: referral to commercial site removed by moderator - original poster has not responded in 6 months!
Reason: referral to commercial site removed by moderator - original poster has not responded in 6 months!
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: How do I make my website pages location independent?
So what you're saying is that newfolder/newfile.php needs to refer to files in common/ ? In that case, to use absolute URLS you'll need to create a file in a known location that knows where it is, like this:
/config.php
Then from whatever file you need, do this:
/config.php
Code: Select all
<?php
define('SITE_ROOT', dirname($_SERVER['SCRIPT_FILENAME']));
?>Code: Select all
<?php
include('config.php'); // or ../config.php, whatever is necessary
include(SITE_ROOT . '/common/header.php');
?>