SkyRanger Posted April 18, 2007 Share Posted April 18, 2007 I am trying to include a file in my code but with a full URL, is it possible to do this? ex: include "http://domain.com/ver/curver.inc"; Quote Link to comment Share on other sites More sharing options...
freakstyle Posted April 18, 2007 Share Posted April 18, 2007 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! Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 18, 2007 Author Share Posted April 18, 2007 lol, it is for version comparison for a script I am writing to the user of the script knows they have the latest version. I never though of using fopen, will try that and see if I can get it to work. Thanks Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 18, 2007 Share Posted April 18, 2007 can you further explain what you're trying to do, and the purpose of this script? Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 18, 2007 Author Share Posted April 18, 2007 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) Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 18, 2007 Share Posted April 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 18, 2007 Author Share Posted April 18, 2007 Doh, I just thought of something, that won't work either because there is a good possibility everybody who installs the script will have this enabled. Have to come up with another way of doing this. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 18, 2007 Share Posted April 18, 2007 look into curl. you may get something useful out of it. Quote Link to comment Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 19, 2007 Author Share Posted April 19, 2007 Awesome frost, thanks I will try that. Quote Link to comment Share on other sites More sharing options...
freakstyle Posted April 20, 2007 Share Posted April 20, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.