0

Happy new year everyone... I have been working on a project and my file structure is

index.php

functions

profile

includes

main forlder is "mysite"

I have a header and footer if I include into the index.php its fine if I include in profile/index.php I get and error

I have tried to use

include($_SERVER['DOCUMENT_ROOT'] . '/header.php');

but have had not success still errors

the error I get when trying to go to profile/index.php

Warning: include(C:/Program Files (x86)/Zend/Apache2/htdocs/header.php): failed to open stream: No such file or directory in C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\profile\index.php on line 2

if you look at the top warning its trying to include from htdocs however the site main folder is mysite

6
  • your header.php is in the "include" and "profile" is a folder right? Commented Jan 4, 2016 at 2:07
  • correct my includes folder has header and nav and footer.php my profile folder has index and edit.php plus I have a admin folder that has pages also in which I need to include the header and footer Commented Jan 4, 2016 at 2:09
  • Have you tried getcwd() instead of $_SERVER['DOCUMENT_ROOT']? Commented Jan 4, 2016 at 2:10
  • and you tried include('../includes/header.php') ? for /profile/index.php? Commented Jan 4, 2016 at 2:11
  • I have not tried getcwd() how would I use that in a include I'm new to php??? Commented Jan 4, 2016 at 2:22

1 Answer 1

2

Your main folder is mysite, so add mysite after $_SERVER['DOCUMENT_ROOT'] for profile/index.php the code will be like this:

include($_SERVER['DOCUMENT_ROOT'] . '/mysite/includes/header.php');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.