![]() |
php include help need hey any one know ho to add many diffrent files from diffrent folders in a single php file.. this code works only for same folder where footer.php place <?php include 'footer.php';?> i want to add different files from diffrent folder like <?php include 'head.php';?> <?php include '/post/mypost.php';?> <?php include '/comment/comment.php';?> <?php include 'footer.php';?> so please help me.. |
Re: php include help need did you try it? everything you typed could work. |
Re: php include help need Check your paths. When you put a "/" in your include statement you're saying to include a file relative to the root of the server, not the document root of your website. Probably what you're looking for is something like: PHP Code: Alternatively you could do something like: PHP Code: |
Re: php include help need What I would recommend is first setting up a file "paths.php" that will have few constants defined to the needed paths, for example: // path to the root folder define('DIR_ROOT',dirname(__FILE__) . '/'); // path to the config folder define('DIR_CONFING', DIR_ROOT . 'config'); etc. include DIR_ROOT . 'footer.php'; include DIR_ROOT . 'head.php'; You would then include it at the top of your script and include the files as needed, this is very prone to movement of the script and you will not have to change your constants often, even if you do, you would simply do so one. Hope this helps. Mr Alexander |
Re: php include help need there's no issue on adding a single '/' before a folder name, and everything you type should work. please re-check your folder paths. I also suggest you use require rather than include require statement will produce a (E_COMPILE_ERROR) and stop the script include statement will only produce a warning (E_WARNING) and the script will continue 'include' could give you more errors because the page will continue to execute even if the file you include is missing and that could affect the next line of codes 'require' will stop the page for further execution. |
| All times are GMT -6. The time now is 06:58 AM. |