I'm not sure if I've posted the title correct as I'm not sure if there's a tehnical title for what I'm looking for - see below.

On my localhost server I have a clone of my VPS files as I wish to sync them via git.

My index.php file contains PHP includes for header and footer:

<?php include(/web/modules/footer.php); ?>

On the VPS the website is hosted inside /home/website. On my localhost (XAMPP on Mac OS X) at htdocs/website.

On localhost the index.php will not load the stylesheets or the footer.php if the / is at the begining of the PHP include.

Is there any way around so I can make XAMPP to behave correctly with /?

Thank you.


Simply put $_SERVER["DOCUMENT_ROOT"] at the start, for example, <?php include($_SERVER["DOCUMENT_ROOT"] . "/web/modules/footer.php"); ?>

The reason why the slash at the start doesn't work is because you are making PHP look in the root of the drive the script is on for footer.php.

Hope this helps.

  • Is there any other way around? Maybe a way around without modifying the PHP code. Unfortunatelly I'm not using only PHP include, but severals plus some basic links that start with /link and are pointing to my localhost rather than my localhost/website.Thank you. – Lee Mar 14 '11 at 22:55
  • Another way would be to set the include_path in php.ini to include the folder your include scripts are in. More information available at PHP's Website: php.net/manual/en/ini.core.php#ini.include-path – Adam Mar 18 '11 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.