Jump to content

Local CURL Request, or file_get_contents locally but to get the result html/xml


Recommended Posts

Hi,

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.

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...

<?php

 

error_reporting(E_ALL|E_STRICT);

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...

<?php

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 ?

i have "allow_url_fopen on" in my php.ini file.

No difference if i turn it on or off though.

 

EDIT: I have uploaded the files to 2 different servers now, a shared server where im havig this issue, and my server where i can set allow_url_fopen there, and it works on my server when its set.

But on the shared server it seems to be ignoring the php.ini file allow_url_fopen .

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.