saint959 Posted April 20, 2009 Share Posted April 20, 2009 Hi All, I am sitting with a problem that i am struggling to figure out. I am using url_fopen to include certain files into a system that we are writing but for some reason PHP is handling .inc files better than .php files. Below is an example: As a test I am including a .php file (database connection details) on another php file but it does not work. The file I am running is called: (URL)/index.php And the file I am trying to include is: (URL)/dbTest.php This then gives me an error. i.e. the connection details in the DpTest.php file does not "run", it does include it but the connection details are not evaluated. I have printed text from the file and it has displayed correctly on index.php. BUT when I change the filename of the dbTest.php file to dpTest.inc it does work. I am completely confused? any help would be hugely appreciated. Link to comment https://forums.phpfreaks.com/topic/154867-including-file-using-php-and-inc/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2009 Share Posted April 20, 2009 When you include a file using its URL, a http request is made (from php back to your web server) to get that file. If the file is a .php file, it is parsed by php and only the HTML output in it is included. This also takes a considerably longer time than if the file is included through the file system. You should be including local files using a file system path, not a URL. You should be using a .php file so that if someone finds your database connection file they cannot just browse to it and see the settings. If you use a .inc file and someone learns or guesses the file name, they can browse to it and get your database connection information. Link to comment https://forums.phpfreaks.com/topic/154867-including-file-using-php-and-inc/#findComment-814496 Share on other sites More sharing options...
saint959 Posted April 20, 2009 Author Share Posted April 20, 2009 Hi PFMaBiSmAd, Thanks for that, yip, that is exactly why i dont want to use .inc files. We have a system that spams over multiple domains and we use one of the domains to store all the "database/backend functions" stuff. For example, www.datastuff.co.za is the database stuff, while www.client1.co.za is the first client. They need to include files from the database domain which we then update on a weekly basis. thereby automatically updating all the clients systems in one go. We were using openbase_dir on our server but we are now in the need to get a second server, hence the need for url_fopen. If you could recommend any alternatives or things that i could look into i would really appreciate it. Thanks again for your time! Link to comment https://forums.phpfreaks.com/topic/154867-including-file-using-php-and-inc/#findComment-814502 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2009 Share Posted April 20, 2009 What exactly are you trying to share? Database connection information, a library of database functions, a database server, or data that gets updated? They need to include files from the database domain which we then update on a weekly basisGeneral purpose application data, that regularly gets updated, and application code should not be in the same file. That violates one the prime rules of programming - separation of code and data. You should not be regularly editing files that contain your application code. Once your code is finished and tested you should not need to touch the files the code is in. Link to comment https://forums.phpfreaks.com/topic/154867-including-file-using-php-and-inc/#findComment-814518 Share on other sites More sharing options...
saint959 Posted April 20, 2009 Author Share Posted April 20, 2009 Hi, They are mainly "functions" which pull data from the database and then display that data on a HTML or PHP page, depending on the type of data that is being pulled and what the next action from the client is going to be. Most of the files that are stored away from the clients domain are addon modules to the application. They are then included depending on if they have activated it or not in their system. So it is not actually data that is being included. Truth be told, the files will not be updated that often, it is only when we improve the Module with new features etc. So basically, we are trying to share functions, db connections. The data that gets updated is stored in a database, and never directly in the files that need to be included. Link to comment https://forums.phpfreaks.com/topic/154867-including-file-using-php-and-inc/#findComment-814530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.