Php include not working? function not being included

Sometimes the current directory isn't what you expect it to be, such as when you include a file from an included file.

I like to use $_SERVER['DOCUMENT_ROOT'] on my includes so that I can always reference them absolutely from the root of my site:

<?php
    include($_SERVER['DOCUMENT_ROOT']."/includes/functions.php");
    doit();
?>

If your includes directory is above your document root, you can use .. to still reference from the root.


So if anyone ever stumbles on this forum because they are having the same issue let me explain what and why it went wrong.

If you include a function not in your directory(e.g c:// or file://) but instead include using http. The include can only return what was echoed in the file, but something like a variable or function will not be shown. So always include functions and variables through a directory


Try require() instead of include. Perhaps include is failing and errors are not being shown.