matfish Posted March 2, 2007 Share Posted March 2, 2007 Hi, How can I include a .php file which is located on a different server/host? include_once("http://www.domain.com/dir/include_this.php"); The above gives: failed to open stream: Connection refused in...blah blah Trying to use one file over several sites Link to comment https://forums.phpfreaks.com/topic/40869-includes-but-different-servers/ Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 <?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> http://uk.php.net/fsockopen Link to comment https://forums.phpfreaks.com/topic/40869-includes-but-different-servers/#findComment-197885 Share on other sites More sharing options...
matfish Posted March 2, 2007 Author Share Posted March 2, 2007 Hi, thanks for the reply. I get: Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in [location of file] on line 17 Warning: fsockopen() [function.fsockopen]: unable to connect to [file location].php:80 in [header location] on line 17 Success (0) You think my hosts may not be allowing the connection? Thanks again Link to comment https://forums.phpfreaks.com/topic/40869-includes-but-different-servers/#findComment-197897 Share on other sites More sharing options...
matfish Posted March 2, 2007 Author Share Posted March 2, 2007 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.domain.com/dir/include_file.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result=curl_exec ($ch); curl_close ($ch); echo $result; the above doesnt work either but doesnt show any errors, does this mean curl is not installed on the host? Will take a week to get a reply from them! Link to comment https://forums.phpfreaks.com/topic/40869-includes-but-different-servers/#findComment-197903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.