Outbound URL requests and PHP

software development

#1

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.


#2

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


#3

[quote]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?[/quote]
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.


Simon Jessey
Keystone Websites | si-blog


#4

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

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.


#5

The recompile worked.

Double thanks!