Jump to content

[SOLVED] Is this possible


SkyRanger

Recommended Posts

hey SkyRanger,

it is not possible to include a file from another domain.

one could always ask the question why you'd want to do that but, there's usually a reason ;)

 

what you could do is use fopen() for that file and then grab the contents of the file and do what every you may want to

do with it. see here: http://us2.php.net/fopen for a detailed explanation.

 

good luck!

Link to comment
Share on other sites

The script I am currently designing is a WHM Hosting Script to manage accounts/billing.  When somebody installs the script on there server I want the script to look back at my server for a version file to read:

 

for example in there admin section it would say:

 

Your Version: 1.0 (Encoded write in script)

Current Version 1.1 (Read from file on my server)

 

Link to comment
Share on other sites

Guest prozente

freakstyle, actually it is possible to include a remote file.

 

In order to do this your PHP configuration must have the following enabled:

 

allow_url_include

allow_url_fopen

Link to comment
Share on other sites

www.php.net/file_get_contents

 

include will only work if the url_fopen is installed, which I would not want to take a chance of everyone having that on.

 

Curl is also another great option, but can be confusing for simple tasks.

 

<?php
$contents = file_get_contents('PATH TO FILE HERE');
?>

 

Should do what you want, but again it is not set in stone that anyone has to have anything installed, even CURL is the same way. So you may want to incorperate 3 or 4 different methods and do a check IE:

 

<?php
if (is_function('file_get_contents')) {
   $contents = file_get_contents('PATH TO FILE HERE');
}elseif (extension_loaded('curl')) {
   // do curl operations here
}elseif (ini_get('allow_url_fopen') == 1) {
   // do fopen reading here
}else {
   die('I cannot determine the version due to server configurations');
}
?>

 

This way you have 3 checks and if one works great if not than the user is SOL and no errors are thrown.

Link to comment
Share on other sites

thanks for correcting me prozente,

yes. you can config apache to allow you to include the remote url. I try to assume that developers do not have full access to their apache files, I understand that some do get this luxury, but on the whole most, I would venture do not. So this option would not work, nor is it secure if he could enable everyone's machine for his function.

 

here's a good write up about changing that setting:

http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html

 

enjoy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.