Jump to content

Problems with php includes from diff file paths. Need help


Lexicon

Recommended Posts

my directory on my mamp server looks like this;

 

root/website/index.php

 

I also have some files in a folder like this

 

root/website/pages/files.php

 

My include code is this

include("functions.php");

 

When I try to include a file from the 'website' folder from a page in the 'pages' folder. It gives me errors that look like this.

Warning: include(functions.php) [function.include]: failed to open stream: No such file or directory in /website/pages/contact.php on line 2

Warning: include() [function.include]: Failed opening 'functions.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/website/pages/contact.php on line 2

 

That's what it looks like.. I can't get it working.

 

that worked. but now when i click on the website logo that is supposed to bring me to

 

root/website/index.php

 

it brings me to

 

root/website/pages/index.php instead... and gives me 404 invalid page or whatever

 

the header code I have is just a link that brings me to /index.php

The links can be controlled by PHP with the help of $_SERVER['DOCUMENT_ROOT'];

 

including example is

 
include($_SERVER['DOCUMENT_ROOT'].'/root/myprojects/blah.php');

//and linking as
echo "<a href=\"" . $_SERVER['DOCUMENT_ROOT'] . "/root/myprojects/blah.php\">My Project List</a>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.