FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Including file with same definition on Win & Linux




Last year I am come in trouble when I create few pages with include function. Problem is quite stupid; I have Win on my computer and Linux on the host. For testing proposes I am using my computer and when I finish just FTP full site. There is not problem and everything is working perfect if is my include folder part of root folder (public_html) on the Linux host. But when I move include folder out of root folder (security reason) I must change my include definition on all pages. I do this one time, but after few days I am changing pages and I need again upload it.

In my life I am pretty lazy man and I don't like too much work, especially if I must do that again and again. That is reason why I am creating simple script what include files on both my Win localhost and Linux host. Here is script:

Code:
<?php
if($_SERVER['HTTP_HOST'] == "localhost") {
define("INC", "C:\Documents and Settings\MyComputer\Desktop\MyTestFolder\include/");
} else {
define("INC", "/home/some_domain/include/");
}
?>


First line check is what host is in use. If is ($_SERVER['HTTP_HOST'] = localhost then switch to my win folder; if is not then switch to (Linux) remote folder on my host. Define function define where PHP must looking for include files. Of course, you must change definitions for your needs. Upper script is only example.

Now, we can include files with the same definition on both servers. For example:

Code:
<?php include_once (INC . "footer.php"); ?>


Good luck! Very Happy



0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.