Load the content of the generated PHP page from another PHP script

I have a PHP script on the server that generates XML data on the fly, say with Content-Disposition: attachment, or with a simple echo, it doesn't matter. I will name this file www.something.com/myOwnScript.php

On another server, in another PHP script, I want to get this file (to avoid "saving the file to disk") as a string (using the path www.something.com/myOwnScript.php) and then manipulate the XML data the script generates.

Is this possible without using web services? security implications?

thanks

+1


a source to share


3 answers


Simple answer, yes:



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

echo '<pre>';
print_r($output);
echo '</pre>';

      

+8


a source


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



+4


a source


If you are using a shared host, you may find that you cannot use file_get_contents

. This is mainly because it is part of the same permission sets that enable deleted files. Anyway...

If you are stuck with this circumstance, you can use 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);     
?>

      

This is more code, but it's still simple. You have the added benefit of being able to send data, set headers, cookies ... anything you could do with a custom browser. This makes it useful when people are trying to block bots.

+1


a source







All Articles