tags:

views:

50

answers:

3

Im a little stuck. I developed a script and for some reason it is converting & in URLs to & automatically.

This is the line that is causing the issue:

$accessToken = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=' . APPID . '&redirect_uri=' . APPURL . 'callback.php&client_secret=' . APISECRET . '&code=' . $_REQUEST['code']);

And this is what the error report is returning:

[20-Jul-2010 15:47:35] PHP Warning:  file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=xxxxxxx&amp;amp;redirect_uri=http://apps.facebook.com/xxxxx/callback.php&amp;amp;client_secret=xxxxxx&amp;amp;code=) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

in /home/pk1no/public_html/video/callback.php on line 8

The funny thing is the same script works on my Joyent dedicated, but not on my HostGator dedicated. I'm a little baffled by it.

+2  A: 

Might it be that the warning message is getting munged, not before the call to file_get_contents, and that there's some other problem?

Grumdrig
This would be my suspicion. Note the `<a>` HTML tags - it would appear the warning message was intended to be echoed rather than going into a text-only log.
ceejayoz
nute
A: 

Is allow_url_fopen enabled on your machine? Otherwise you cannot open files via URL.

You could also try to wrap the URL with urlencode().

StefanMacke
Yes it is on. I tried with urlencode(). Let me see if the log file produces a different error when using that.
Jamie Redmond
nute
Paul Dixon
A: 

It's only the error message which has got HTML entities in so that it is presented correctly in your browser.

You're not building your URL correctly, most likely rendering it unparsable by the URL fopen wrappers. Use urlencode to wrap anything which might contain some non URL-safe characters...

$url='https://graph.facebook.com/oauth/access_token'.
    '?client_id=' . urlencode(APPID) .
    '&redirect_uri=' . urlencode(APPURL) . 'callback.php'.
    '&client_secret=' . urlencode(APISECRET) . 
    '&code=' . urlencode($_REQUEST['code']);

$accessToken = file_get_contents($url);
Paul Dixon