B34ST Posted July 11, 2007 Share Posted July 11, 2007 Hi I was wondering if it was possible to include a php file which is hosted on a different domain? for example i have 2 domains http://www.example.com and http://example2.com i have a php script on example.com which i want to include in another script on example2.com. I tried to just simply include the script: include('http://www.example.com/testscript.php'); but this does not seem to work. When I checked the manual it said that this is possible as long as the php version is greater than 4.3.0 (which mine is on both domains) and allow_url_fopen is enabled ehich it is on both domains. am i missing something? or is there another way of doing this? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 I suggest use curl Quote Link to comment Share on other sites More sharing options...
B34ST Posted July 11, 2007 Author Share Posted July 11, 2007 does curl process php? or just read the contents of the file ie the html output? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 i dont know what your talking about but curl reads the page in your page as it is you can use the form of the other site as they are on that site but if you think like use the php code i dont think you can Quote Link to comment Share on other sites More sharing options...
Rojay Posted July 11, 2007 Share Posted July 11, 2007 curl still uses http requests which will send the output html i recommend to add a line at the begining of the PHP file like this <? if( $_SERVER['HTTP_REFERER'] == 'http://example.com') { echo file_get_contents($_SERVER['PHP_SELF']); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
B34ST Posted July 11, 2007 Author Share Posted July 11, 2007 its the variables that i need to grab, would this still work for that? Quote Link to comment Share on other sites More sharing options...
prime Posted July 12, 2007 Share Posted July 12, 2007 you could try using local links instead of global..... since when you use global it accesses the html instead of the php Quote Link to comment Share on other sites More sharing options...
Rojay Posted July 12, 2007 Share Posted July 12, 2007 <? if( $_SERVER['HTTP_REFERER'] == 'http://www.example.com') { echo file_get_contents($_SERVER['SCRIPT_FILENAME']); exit(); } ?> just replace http://www.example.com with the actual URL... the FULL URL Quote Link to comment Share on other sites More sharing options...
trq Posted July 12, 2007 Share Posted July 12, 2007 You an only include a remote file if the appropriate url wrappers are enabled. On most sahred hosts, these are disabled. Rojay, Prime and Teng... the op doesn't want the output of a php file, but wants to include a remote php file, two different things. Quote Link to comment Share on other sites More sharing options...
Rojay Posted July 12, 2007 Share Posted July 12, 2007 the code i gave him will do the same exact thing -only and if only http://example.com tried to access the file, the file will be sent unparsed/raw else send the normal output 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.