• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

php question get remote url

xoggoth

More fingers than teeth
Thanks received
1,183
Still trying to sort out a currency conversion on my site and having a bash at some php:-

$contents = file_get_contents(urlencode('https://select.worldpay.com/wcc/info?op=rates&instId=xxxxx'));
echo $contents;

This gives me:

Warning: file_get_contents(blah blah) [function.file-get-contents]: failed to open stream: No such file or directory in (my host directory)/blahblah.php

Why is it looking for the file locally? Get same with other urls like www.google.com but as I understand it this should work with a remote URL if echo ini_get("allow_url_fopen"); returns 1 which it does.

Cheers
 
Still trying to sort out a currency conversion on my site and having a bash at some php:-

$contents = file_get_contents(urlencode('https://select.worldpay.com/wcc/info?op=rates&instId=xxxxx'));
echo $contents;

This gives me:

Warning: file_get_contents(blah blah) [function.file-get-contents]: failed to open stream: No such file or directory in (my host directory)/blahblah.php

Why is it looking for the file locally? Get same with other urls like www.google.com but as I understand it this should work with a remote URL if echo ini_get("allow_url_fopen"); returns 1 which it does.

Cheers

file_get_contents() doesn't accept a non-local URI as a parameter AFAIK.

Would be a bit of a security disaster if it did really, wouldn't it?

There are SOAP services and so on for real-time currency conversions, but normally subscriptions.
 
Try:

Code:
$contents = file_get_contents(htmlentities('https://select.worldpay.com/wcc/info?op=rates&instId=xxxxx'));
echo $contents;

Instead
 
file_get_contents() doesn't accept a non-local URI as a parameter AFAIK.

Would be a bit of a security disaster if it did really, wouldn't it?

There are SOAP services and so on for real-time currency conversions, but normally subscriptions.

It does depending on your php.ini settings, you can also override php.ini with:

Code:
ini_set(allow_url_fopen, 1);

However some host's disable this.
 
Correct.

But is that still the php.ini default? Hope not :eek:

PHP! Bag 'o tulipe!

How do you expect a server-side script to retrieve data from another server if it can't open a URL? This is one of the fundamental aspects of the way the web works. It doesn't exist solely for the purpose of providing HTML pages to browsers.

As far as I can see the only possible reason for a hosting provider to disable this would be over bandwidth concerns. I wouldn't use a hosting provider that didn't allow this.

xoggoth: you might have more success using the cURL functions. For retrieving an https URL, your hosting provider will have to have included OpenSSL support (or some equivalent library) in their PHP installation (which they should have done if they're any good).

You can check by uploading a temporary file containing the following:
Code:
<?php
phpinfo()
?>
as, say, info.php and going to that page. Scroll down to the "Configuration" section after the copyright notices (about one screen down). The "PHP Core" section should include a row for allow_url_fopen which should have the "Local value" of "on". Scrolling further, you should have subsections for "curl", meaning cURL functions are installed, and "openssl", meaning you can use https URLs - for both of those the first row should state that support is "enabled", otherwise you're out of luck.

Oh, and then remove the info.php file, as it provides information about your server that the rest of the world shouldn't be allowed to see :nerd
 
Depends which PHP distro you get I would assume, but the default php.ini you get from php.net has it on by default.

At the end of the day the webserver admin should know about it and decide if it should be on or off, as there are many legitimate uses for it. Its the so called web admins who don't check the default php.ini who are a bag 'o tulipe, not PHP itself.
 
How do you expect a server-side script to retrieve data from another server if it can't open a URL? This is one of the fundamental aspects of the way the web works. It doesn't exist solely for the purpose of providing HTML pages to browsers.

I know that you silly bonobo! It should not, however, be enabled by default.
 
Last edited: 20:36
How do you expect a server-side script to retrieve data from another server if it can't open a URL? This is one of the fundamental aspects of the way the web works. It doesn't exist solely for the purpose of providing HTML pages to browsers.

As far as I can see the only possible reason for a hosting provider to disable this would be over bandwidth concerns. I wouldn't use a hosting provider that didn't allow this.

xoggoth: you might have more success using the cURL functions. For retrieving an https URL, your hosting provider will have to have included OpenSSL support (or some equivalent library) in their PHP installation (which they should have done if they're any good).

You can check by uploading a temporary file containing the following:
Code:
<?php
phpinfo()
?>
as, say, info.php and going to that page. Scroll down to the "Configuration" section after the copyright notices (about one screen down). The "PHP Core" section should include a row for allow_url_fopen which should have the "Local value" of "on". Scrolling further, you should have subsections for "curl", meaning cURL functions are installed, and "openssl", meaning you can use https URLs - for both of those the first row should state that support is "enabled", otherwise you're out of luck.

Oh, and then remove the info.php file, as it provides information about your server that the rest of the world shouldn't be allowed to see :nerd

Unless of course your friendly web admin has set:

Code:
[FONT=verdana][SIZE=2][COLOR=#000000]disable_functions = phpinfo
[/COLOR][/SIZE][/FONT]
in the php.ini :smokin
 
Still trying to sort out a currency conversion on my site and having a bash at some php:-

$contents = file_get_contents(urlencode('https://select.worldpay.com/wcc/info?op=rates&instId=xxxxx'));
echo $contents;

This gives me:

Warning: file_get_contents(blah blah) [function.file-get-contents]: failed to open stream: No such file or directory in (my host directory)/blahblah.php

Why is it looking for the file locally? Get same with other urls like www.google.com but as I understand it this should work with a remote URL if echo ini_get("allow_url_fopen"); returns 1 which it does.

Cheers

Actually xog, your problem is almost certainly the urlencode call: this turns the slashes and so on into their urlencoded form.

Assuming xxxxx represents some value that might contain special characters and needs URLEncoding, try

Code:
$encoded_inst_id = urlencode($inst_id);
$contents = file_get_contents('https://select.worldpay.com/wcc/info?op=rates&instId='.$encoded_inst_id);
echo $contents;

Or have a look at the first example at http://www.php.net/manual/en/features.remote-files.php if you want finer control over file processing.
 

Advertisers

Back
Top