Current location: Hot Scripts Forums » Programming Languages » PHP » include()


include()

Reply
  #1 (permalink)  
Old 06-25-06, 10:04 PM
jumbo1 jumbo1 is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 118
Thanks: 0
Thanked 0 Times in 0 Posts
include()

Hi there

i know how to use the include() funtion, BUT there's my problem: i got a server with several sites of mine, and each site has its own CPanel... and I want to design some PHP files that are to be in common among all these sites... and instead of making a copy of the PHP file in every CPanel, I want to store it in one place and make the other sites' files point to it by including something like:

Code:
include('http://www.centralsite.com/mainpage.php');
but this format does not work... is there a way to perform the task i want??

thank you
Reply With Quote
  #2 (permalink)  
Old 06-25-06, 10:41 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Yes, but it's not recommended.



Remove the start and end tags (the first <?php and last ?>) from the files you want to include and rename them to a .txt extension.

So (hypothetically) mainpage.php:
PHP Code:

<?php


$host 
$_SERVER['HTTP_HOST'];

echo 
$host;

?>
...becomes mainpage.txt:
Code:
$host = $_SERVER['HTTP_HOST'];

echo $host;
Then, to access the file so it parses correctly, use this code:
PHP Code:

<?php


eval( file_get_contents'http://www.centralsite.com/mainpage.txt' ) );

?>
The included file should not have a .php extension since the script is simply grabbing the contents of the file and evaluating it as PHP code. If you name it .php, any internal PHP tags could be parsed by the server it's residing on before being sent to the requesting server.

Any file included should be written as a typical PHP file, except you must omit only the start and end PHP tags, and not give it a .php entension.



The reason this is not recommended is because the file must be public to be seen by external servers, and the code is readable because it must be readable by the requesting servers. Because of this, anyone can access and read your code. So try to obfuscate it with really long and weird directory/file names.

Also, if the host server goes down, all external sites using the hosted files cease to function as well.
__________________
The toxic ZCE

Last edited by Keith; 06-25-06 at 10:55 PM.
Reply With Quote
  #3 (permalink)  
Old 06-25-06, 11:58 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
It might be possible to make use of the include_path setting to allow this to function, in the same way that PEAR classes can be included from a common location.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #4 (permalink)  
Old 06-27-06, 06:02 AM
juggernaut juggernaut is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not too sure this would work, but if you have all those sites on one server at some point they all have the same path, so the file could be placed in a directory common to all sites... But as I said, I'm not sure this would work...
Reply With Quote
  #5 (permalink)  
Old 06-27-06, 09:36 AM
jumbo1 jumbo1 is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 118
Thanks: 0
Thanked 0 Times in 0 Posts
thank you guys

keith, yea, as u said, there's a serious security gap in the method u pointed to... still, it's a valid one... i only need to test it and make sure it works...

unfortunately, there doesnt seem to be a common directory for all sites on the server, and if there were such a dir, i wont use it anyway because it would be accessible by all people who have a site hosted on the same server (it's a shared one).

Thank you
Reply With Quote
  #6 (permalink)  
Old 06-27-06, 10:58 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
I didn't mention the reduction in load time by having to access a file across the internet on each page load.

If you do go that route, I'd suggest using some type of local file caching so you only have to grab the file, say, once every 15 minutes... or however frequent you want to make it.
__________________
The toxic ZCE
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Including a File but cant use the include tag Dainbramaged05 PHP 4 10-10-05 07:00 AM
Page dependent include - how? CutAndPaste PHP 9 08-27-05 04:20 PM
links script that i could just include Andrey Script Requests 1 02-26-05 12:01 PM
PHP help... Orchidsdance PHP 8 09-25-04 07:58 PM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 10:15 AM


All times are GMT -5. The time now is 07:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.