I have a PHP script on a server that generates the XML data on the fly, say with Content-Disposition:attachment or with simple echo, doesn't matter. I'll name this file www.something.com/myOwnScript.php
我在服务器上有一个PHP脚本,可以动态生成XML数据,例如Content-Disposition:附件或简单的echo,无关紧要。我将这个文件命名为www.something.com/myOwnScript.php
On another server, in another PHP script I want to be able to get this file (to avoid "saving file to disk") as a string (using the path www.something.com/myOwnScript.php) and then manipulate XML data that the script generates.
在另一台服务器上,在另一个PHP脚本中,我希望能够将此文件(以避免“将文件保存到磁盘”)作为字符串(使用路径www.something.com/myOwnScript.php)然后操作XML数据脚本生成。
Is this possible without using web services? security implications?
这可能不使用Web服务吗?安全影响?
Thanks
Simple answer, yes:
答案简单,是的:
$output = file_get_contents('http://www.something.com/myOwnScript.php');
echo '<pre>';
print_r($output);
echo '</pre>';
If you want more control over how you request the data (spoof headers, send post fields etc.) you should look into cURL. link text
如果您想要更好地控制请求数据的方式(欺骗标题,发送帖子字段等),您应该查看cURL。链接文字
If you're on a shared host, you might find that you cannot use file_get_contents
. This mainly because it is part of the same permission sets that allow you to include remote files. Anyway...
如果您在共享主机上,则可能会发现无法使用file_get_contents。这主要是因为它是允许您包含远程文件的相同权限集的一部分。无论如何...
If you're stuck in that circumstance, you might be able to use CURL:
如果您遇到这种情况,您可以使用CURL:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
?>
It is more code, but it's still simple. You have the added benefit of being able to post data, set headers, cookies... anything you could do with a highly configurable browser. This makes it useful when people attempt to block bots.
这是更多的代码,但它仍然很简单。您可以发布数据,设置标题,Cookie以及使用高度可配置的浏览器执行的任何操作。这使得当人们试图阻止僵尸程序时它很有用。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/05/12/e76a2d4264c8fdd8829be3ce54d90b81.html。