Outbound URL requests and PHP

Outbound URL requests and PHP

Posted by: spzr0
Posted on: 2005-11-14 17:21:00

I'm using a third-party script on my site that is encoded by SourceGuardian, thus I cannot modify any of the original code. In contacting this company's support department, they have indicated that their scripts use file_get_contents() via URLs to fetch external pages. This is currently failing. I made a little test script:

<?php
$test = file_get_contents('http://www.google.com/index.html');
echo $test;
?>

The output error is:
Warning: file_get_contents(): URL file-access is disabled in the server configuration in {path-to-file} on line 5

How can I work around this? Do I need to compile PHP myself? Would this even fix the problem? Are there any simpler solutions?

Thanks for any input.

Re: Outbound URL requests and PHP

Posted by: matttail
Posted on: 2005-11-14 19:05:00

The search feature is wonderful.

Yes, you'd have to conplie your own version of php to enable this. I'd bet you're better off finding an other script, or tell the company to re-code it.



-Matttail

Re: Outbound URL requests and PHP

Posted by: scjessey
Posted on: 2005-11-15 04:57:00

In reply to:

I'm using a third-party script on my site that is encoded by SourceGuardian, thus I cannot modify any of the original code. In contacting this company's support department, they have indicated that their scripts use file_get_contents() via URLs to fetch external pages. This is currently failing. I made a little test script:

<?php
$test = file_get_contents('http://www.google.com/index.html');
echo $test;
?>

How can I work around this?


Compiling your own version of PHP would do the trick; however, it would be better to get the original developers to modify their code to use the cURL extension when allow_url_fopen has been disabled. A rewrite of your example using cURL would look like this:

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www.google.com/index.html');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$test = curl_exec($ch);
curl_close($ch);
echo $test;
?>

For more information on this issue, see this page of the DreamHost wiki.

Re: Outbound URL requests and PHP

Posted by: spzr0
Posted on: 2005-11-16 05:50:00

Thank you both for the help.

Unfortunately using another script isn't an option as my boss purchased it months ago, without advisement. As for getting the company to recode it - they're barely responding to my general support requests (like missing files) as it is, so unfortunately I doubt they'd recode anything for me. Meh. ;)

Gotta work with what I got, so I'm currently recompiling. The wiki was a great help in this regard - I had searched through the Knowledge Base and didn't find anything relating to what I was looking for, but the wiki had it there the whole time.

Thanks again.

Re: Outbound URL requests and PHP

Posted by: spzr0
Posted on: 2005-11-16 07:50:00

The recompile worked.

Double thanks!

Tags: test scriptoutboundfetchurlsscriptsphp