tomt

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 <?

php

 info(); ?>.

// $my_path = $_SERVER["SCRIPT_URL"];
$my_path = $_SERVER["SCRIPT_NAME"];
$pathArray = pathinfo_im($my_path);
$thisFileName = $pathArray[basename];
$directoryName = $pathArray[dirname];
if ($directoryName !=  "/"Applause { $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

vsloathe

It should by default use the directory that the script is running from as your base directory. If it's not, you can get it by doing


<?

php

 
$currentDirectory = getcwd();
?>

tomt

Thanks, that worked. What I am finding is the problems lie in the fact that godaddy (my hosting plan) uses version 5 of

php

  while hostigator (my customer's) uses 4.4. A lot of the functions I found in the

php

  online manual are only available with version 5. Says so at the top of the each function description page. Of course I didn't see that at the beginning of this project. So I am having to search for alternatives. I haven't given up, I am getting there.

Tom

ratthing

You may be able to get hostgator to use

PHP

  5 by adding this in your .htaccess file:


AddHandler x-httpd-

php

 5 .

php

  .phtml .

php

 s .

php

 5


My host uses

PHP

  4 by default, but by adding that I was able to use

PHP

  5.

=RT=


Perkiset's Place Home   Politics @ Perkiset's