I have written config.php
, head.php
in my public_html
, now i need them in the new folder (public_html/test/gallery
) where test is a sub-domain using require
and include
respectively.
<?php
require_once"../config.php";
require_once"../func.php";
include_once"../head.php";
echo "are u mad";
?>
It keeps returning a blank page. How do I do that?
Use absolute paths always, and you'll never bang your head like this again.
include_once "/var/www/path/to/your/script.php";
And also, you can debug this much more effectively if you put the following at the top of your pages which you are having trouble with:
ini_set("display_errors","On");
error_reporting(-1);
I like to include all files relative to the document root like so:
include_once $_SERVER['DOCUMENT_ROOT'] . "/depends/where/code/is.php";
the good thing is that all files will be in relation to one source root. This makes your code more like fluid!
*Tip: you can also specify an include path in your php.ini config file. This helps PHP find your file faster too.