file_get_contents - php

Lucipher6

New Member
Messages
6
Reaction score
0
Points
0
This isn't so much a programming question, though I wasn't sure where else to post.

When Cossacks went down or with the DNS updates (not sure which, similar times) the function which uses file_get_contents stopped working - it worked fine before this.

The error each update gets.
[FONT=calibri, arial, verdana]Warning: file_get_contents(http://hiscore.runescape.com/hiscorepersonal.ws?user1=P_Gertrude) [function.file-get-contents]: failed to open stream: Success in /home/ianh/public_html/updater.php on line 113[/FONT]

Someone else I know a website on another free hosting site which was used for a 2 day war whilst the function hasn't been working - the exact same function worked there.

I read over the topic "Name Server Updates" and I'm pretty sure I don't use custom DNS settings. Any ideas what the problem could be?
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
I've had exactly the same problem (yes, also with hiscore.runescape.com) and I'm guessing it's some nameserver issue, which causes the server to resolve the domain wrong. So I found out what the ip of hiscore.runescape.com is, but that resolves in coreproxies.runescape.com, so using the ip instead of the domain doesn't work... So I took a look at the http request headers, and apparantly both the requested url and the requested host are part of the http request. So you can actually request the page "http://168.75.184.54" (coreproxies ip address) with the right headers, and you will receive the page you want.

This is the code:
PHP:
@$hiscoredata = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user");
becomes:
PHP:
$context_options = array(
	'http' => array (
		'method' => 'GET',
		'header' =>
			  'GET /index_lite.ws?player='.rawurlencode($user).' HTTP/1.1\r\n'
			. 'Host: hiscore.runescape.com\r\n'
			. 'Connection: close\r\n'
	)
);
$context = stream_context_create($context_options);
@$hiscoredata = file_get_contents("http://168.75.184.54", false, $context);

Note: if the ip of coreproxies would change, you would have to update this.

- Marshian
 
Last edited:

Lucipher6

New Member
Messages
6
Reaction score
0
Points
0
Slow in replying to this, due to trying multiple different ways around it.

Your function didn't work for me, got the error:
Warning: file_get_contents(http://168.75.184.54) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not found in C:\xampplite\htdocs\updater.php on line 121

Also trying with another function - using fopen and fread to get the information:
Warning: fopen(http://hiscore.runescape.com/index_lite.ws?player=P_Gertrude) [function.fopen]: failed to open stream: Success in /home/ianh/public_html/updater.php on line 120

The fopen and fread definately worked on localhost.
 
Top