1

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

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.

Is this possible without using web services? security implications?

Thanks

4

3 回答 3

8

Simple answer, yes:

$output = file_get_contents('http://www.something.com/myOwnScript.php');

echo '<pre>';
print_r($output);
echo '</pre>';
于 2009-05-12T19:01:54.127 回答
4

If you want more control over how you request the data (spoof headers, send post fields etc.) you should look into cURL. link text

于 2009-05-12T19:03:25.047 回答
1

如果您在共享主机上,您可能会发现无法使用file_get_contents. 这主要是因为它是允许您包含远程文件的相同权限集的一部分。反正...

如果你被困在这种情况下,你也许可以使用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);     
?>

它是更多的代码,但它仍然很简单。您还可以通过高度可配置的浏览器发布数据、设置标题、cookies……任何您可以做的事情。当人们试图阻止机器人时,这非常有用。

于 2009-05-12T19:07:34.837 回答