
![]() |
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 <?phpinfo(); ?>.// $my_path = $_SERVER["SCRIPT_URL"]; $my_path = $_SERVER["SCRIPT_NAME"]; $pathArray = pathinfo_im($my_path); $thisFileName = $pathArray[basename]; $directoryName = $pathArray[dirname]; if ($directoryName != "/" ![]() 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
phpwhile hostigator (my customer's) uses 4.4. A lot of the functions I found in thephponline 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
PHP5 by adding this in your .htaccess file:AddHandler x-httpd- php5 .php.phtml .phps .php5My host uses PHP4 by default, but by adding that I was able to usePHP5.=RT= |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads