• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Local CURL Request, or file_get_contents locally but to get the result html/xml rather than the file itself.

[eluser]Andrew Stilliard[/eluser]
i need to find a php core function, or even one built for/into CodeIgniter, that would allow me to locally on a domain get the result of a php file.

The php file generates xml, its stand alone but something i built a long time ago, what it does is great but complex and working it into the new system would take too long.
Its on the same domain as the new system, just in a sub directly, and to make it more complex, the file called is for example file.xml, but actually its using .htaccess and an index .php page to run it.
Now if this file was on a different domain, i could call file_get_contents and get the file, and it would give me the result xml, but its on the same domain which would typically give me the php code, the actual file content rather than its result. but even that i could solve by using eval on it. but because this file only exists via htaccess and an index.php page i cant even do that.

Even the eval option would not be great as i may have some functions with the same names in both that file and the new project which would cause issues.

After that ramble of an explanation basically what i need is a file_get_contetns that would work as-if its the user viewing it, or as-if its on another domain.
I have tried curl requests but no such luck, so any help would be brilliant and if there is a set of curl params or stream params for file_get_contents i could use please point me in there direction.

Thanks in advance.

[eluser]Burak Guzel[/eluser]
I don't think it matters whether or not it is on the same domain. Just make sure you pass the full URL to file_get_contents, rather than a relative path.

[eluser]Andrew Stilliard[/eluser]
Thanks for the reply, i had been trying using it with the full path but no luck.
But i now find i had error reporting turned off, and the file_get_contents was giving this error...

Warning: file_get_contents(http://domain/test2.php) [function.file-get-contents]: failed to open stream: Connection refused in /location/domain/public_html/test.php on line 8

This is the error given from a test.php file which simply runs the following...

ini_set('display_errors', 'on');

$file = "http://domain/test2.php";

$fileContent = file_get_contents($file);

echo "Result: " . $fileContent;


and test2.php contains the very very simple test content of...
echo "hello";

So im expecting to run test.php and for "Result: hello" to be printed to my browser.
The file definetly exists when i go directly to it in my browser, but the error remains.
I assume this is to do with some server settings, maybe something blocking internal requests using http ?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.