a.stilliard Posted June 9, 2010 Share Posted June 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/ Share on other sites More sharing options...
trq Posted June 10, 2010 Share Posted June 10, 2010 file_get_contents() will work fine, you just need to call the file via a url (and have the server process it) instead of a file system path. eg; $xml = file_get_contents('http://yourdomain.com/file.xml'); Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070145 Share on other sites More sharing options...
a.stilliard Posted June 10, 2010 Author Share Posted June 10, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070245 Share on other sites More sharing options...
trq Posted June 10, 2010 Share Posted June 10, 2010 You need to enable allow_url_fopen. Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070259 Share on other sites More sharing options...
a.stilliard Posted June 10, 2010 Author Share Posted June 10, 2010 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 . Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070274 Share on other sites More sharing options...
trq Posted June 10, 2010 Share Posted June 10, 2010 Shared server will often have this disabled. You may be out of luck. Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070275 Share on other sites More sharing options...
a.stilliard Posted June 10, 2010 Author Share Posted June 10, 2010 Thats what im fearing now, just loggin a ticket to my hosting company about it. Thanks for your help anyway thorpe. Quote Link to comment https://forums.phpfreaks.com/topic/204336-local-curl-request-or-file_get_contents-locally-but-to-get-the-result-htmlxml/#findComment-1070278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.