I have a php file, and I want to include another php file that have css link tags and javascript source tags, but when I try to include them, it doesn\'t get added to the pa
PHP's include is server-side, so you need to use the server side path. It is better to use dirname(__FILE__)
instead of $_SERVER['SSCRIPT_NAME']
, but $_SERVER['SERVER_NAME']
is absolutely wrong.
Try:
include dirname(__FILE__)."/common.php";
Or if the file you want to include is not on the same directory, change the path. For example for a parent directory, use dirname(__FILE__)."/../common.php"
.
Note that some might suggest using include "./common.php"
or similar. This could work, but will most likely fail when the script invoking include
is actually being included by another script in another directory. Using dirname(__FILE__)."/common.php"
will eliminate this problem.