Log in

View Full Version : file_get_contents() returns diff value on server and browser



jonas-e
08-01-2009, 02:56 PM
I want to get some xml data from another server and process it for my own page.

So, to get startet I do something like this:

$url = 'http://picasaweb.google.com/data/feed/base/user/jonas.ellehauge?kind=photo&max-results=5&start-index=600&thumbsize=400';
$xml = file_get_contents($url);
echo $xml;


Which happens to return different xml compared to if I put the same URL in my browser - i.e. less xml without the links etc I am looking for.

I tried extending it a bit, like this:

$opts = array('http' =>
array(
'method' => 'GET',
'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1 (.NET CLR 3.5.30729)'
)
);
$context = stream_context_create($opts);
$xml = file_get_contents($url, null, $context);
echo $xml;

- pretending to be a browser. That doesn't work either.

If I do it with a different webservice, i.e. this:

$url = "http://kort.arealinfo.dk/wms?service=wms&servicename=landsdaekkende_wms&VERSION=1.1.1&REQUEST=GetCapabilities";
- It works fine - I get the same as I would in the browser.

Any suggestions what I might do?

jonas-e
08-03-2009, 06:33 PM
I found the reason: I send an unauthenticated request to the Picasa feed from the server, but I was logged in to my Google account when viewing the feed in my browser.

I feel rather silly not noticing by myself .. :(