0

I use this page to get the current currency conversion: http://finance.google.co.uk/finance/converter?a=1&from=EUR&to=GBP

It has worked okay for over a year using file_get_contents but all of a sudden it stopped working.

I then tried curl and it is showing the following: 302 Moved The document has moved here.

Why would the url work ok in the browser but not work from file_get_contents or curl?

When I load the page in a browser the url doesn't redirect or anything like that.

Thank you

Dan
  • 103
  • 11
  • This seems to work with `file_get_contents`, just checked – Alex Yokisama Mar 13 '18 at 20:04
  • @AlexYokisama Thank you for your reply. When I try file_get_contents I get the error message: Warning: file_get_contents(https://finance.google.com/finance/converter?a=1&from=USD&to=GBP): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in (and also get the same with the url I gave in my original post) – Dan Mar 13 '18 at 20:13
  • That's strange. What I do is just `var_dump(file_get_contents("https://finance.google.com/finance/converter?a=1&from=USD&to=GBP"));` and I get it without troubles. Didn't you change something on your server? Maybe some settings or something like that? – Alex Yokisama Mar 13 '18 at 20:17
  • @AlexYokisama Very stange, I just get the error message when I try. – Dan Mar 13 '18 at 20:37

3 Answers3

0

It seems like Google has changed their URLs/endpoints.

Use this Google Finance Endpoint instead:

https://finance.google.com/finance/converter?a=1&from=EUR&to=GBP

Edit: 302 moved... The document has moved here can also be caused by a malware infection. You can find more information here: https://productforums.google.com/forum/#!topic/websearch/hvkhGWCfNsE

eMM
  • 318
  • 5
  • 15
  • Thank you for your reply. I have tried the url you suggested with the same result both with file_get_contents and CURL. – Dan Mar 13 '18 at 20:12
  • https://onlinecurl.com You can use this online tool to test your curl commands. Give it a try, it works! – eMM Mar 13 '18 at 20:17
  • I have just done a scan of my laptop with malwarebytes and it didn't detect any malware. The hosts file is empty, is that normal? I have recently got a new laptop, the hosts file on my other had lots of different entries and I can't remember what the default hosts file looks like. I have tried the website you provided and it works fine on that it just doesn't work from my curl script running on my laptop or server. – Dan Mar 13 '18 at 20:45
  • @DanielOrmerod what is the OS in your new laptop? And what is your server OS and PHP version? – eMM Mar 13 '18 at 21:03
  • The OS is Windows 10 on the laptop (also the same on my old laptop). The server OS is linux and the php version is 5.6.24. – Dan Mar 13 '18 at 21:07
  • Make sure you didn't miss any of the following steps for your Windows laptop: https://stackoverflow.com/a/16216825/3172722 – eMM Mar 13 '18 at 21:11
  • Apologies I have given you incorrect information (it's making me really stressed as our company relies on this for importing our orders from ebay/amazon channels) when I said I am running it from my laptop I am running it from our website manually in the browser which means it is on the server only that it isn't working on. – Dan Mar 13 '18 at 21:14
  • @DanielOrmerod Try this one with the -L flag: $output = shell_exec('curl -L http://finance.google.co.uk/finance/converter?a=1&from=EUR&to=GBP'); echo "
    $output
    ";
    – eMM Mar 13 '18 at 21:24
  • I tried what you suggested and it shows the google logo with the error message "404. That's an error. The requested URL /search was not found on this server. That’s all we know." – Dan Mar 13 '18 at 21:31
  • Could something on the server itself be redirecting the url? – Dan Mar 13 '18 at 21:31
  • Also try $output = shell_exec('curl -L -k https://finance.google.com/finance/converter?a=1&from=EUR&to=GBP'); echo "
    $output
    ";
    – eMM Mar 13 '18 at 21:40
  • I have tried and again I get the same response. I have actually moved to another website instead of google to get the currency so I am happy with it now. Thank you for all your help it is much appreciated and if I do find a solution to the google problem I will be sure to let you know. Thanks again! – Dan Mar 13 '18 at 22:24
0

With curl you can tell it to automatically follow redirects via:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Whether or not this is a safe choice is a completely separate topic.

MonkeyZeus
  • 18,445
  • 3
  • 30
  • 67
  • Thank you for your answer. I tried using that before I asked the question. Setting the follow location redirects the page to https://finance.google.com/search?q=finance which doesn't exist. – Dan Mar 13 '18 at 20:42
  • @DanielOrmerod Strange, `file_get_contents( 'http://finance.google.co.uk/finance/converter?a=1&from=EUR&to=GBP ')` works no problem for me; PHP 5.2 through 7.2. Some thing between your computer and Google is issuing a redirect. Possible culprits include but are not limited to antivirus, firewall, virus, router, website blockers, your ISP, VPN, proxy, etc... – MonkeyZeus Mar 13 '18 at 20:49
  • Thank you I will look into the possible causes of the redirect. – Dan Mar 13 '18 at 21:08
0

People report problems with Google Finance currency converter page like http://finance.google.com/finance/converter?a=1&from=USD&to=EUR. I haven't found any official notices about this from Google yet. However it's known that Google recently (November 2017) revamped their whole Google Finance

we’re retiring a few features of the original Google Finance

There is a good chance Google is either updates the currency converter endpoint or discontinuing it at all.

Sergey Alekseev
  • 8,470
  • 6
  • 31
  • 47