What is the proper way to do includes in php? In coldfusion I can include a file to a page like this:
<cfinclude template = "/include/com.cfm">
It wouldn't matter what directory the calling page is from, the code would go out to root directory of the domain go back up the tree to the directory include and get the include file. Simple one little line of code.
I can't get that to work in php. I did come up with the following code that does work on my test site. My test site is being hosted by godaddy. It doesn't work on my customer's site, which is on hostigator. The commented out line is what I had first, but I didn't see that variable on hostigator when I did a <? phpinfo(); ?>.
// $my_path = $_SERVER["SCRIPT_URL"];
$my_path = $_SERVER["SCRIPT_NAME"];
$pathArray = pathinfo_im($my_path);
$thisFileName = $pathArray[basename];
$directoryName = $pathArray[dirname];
if ($directoryName != "/") { $d = "../include";$a = $directoryName;} else { $d = "./include";$a = "home";}
include "$d/com.php";
Seems kind of convoluted compared to coldfusion. What am I missing here?
Thanks,
Tom