Content pulling with php

Status
Not open for further replies.

absenm

New Member
Messages
16
Reaction score
0
Points
0
I am encountering a nightmare of a problem when it comes to acquiring remote data from a website to include in the php files of my website. My website is a Runescape fan site and Jagex, the company that makes the online game, has created a striped down version of their player high scores page so that fan sites can easily incorporate the data into their sites. The page from their site looks like this:

683917,1127,4423878 910344,69,726876 721075,68,615536 921816,70,774510 898926,69,695525 -1,-1,-1 1119603,44,56683 -1,-1,-1 1449695,54,152509 1984951,50,104415 1300840,37,27900 1073647,60,274972 1288527,49,93270 1150143,46,73547 973616,50,105027 782088,62,338221 519020,37,27538 525863,46,70160 617990,49,91733 591071,38,33385 441811,30,13394 -1,-1,-1 -1,-1,-1 621021,30,13433 167027,39,34321 -1,-1 -1,-1 -1,-1 -1,-1

It is specifically designed for easy parsing. My problem is that I can not seem to get my php file to recognize the files address. And before anyone asks, I requested and received medium level php security from x10hosting. And I did recieve the second e-mail. And Jagex made the page I am requesting specifically for php retrieval so they don't have any blocks on it. Also, the link, http://hiscore.runescape.com/index_lite.ws?player=absenm, works perfectly in a browser. I fear that it may be the 'hiscore' subdomain that may be the issue, but I am not sure.

There are dozens of scripts available on the internet designed to retrieve this information page from Runescape. Right now I am only concerned with the connectivity, not the parsing abilities. There is no need to worry about the parsing if there is nothing to parse. Anyway, all of the scripts I tried, and I tried everyone I could find, comes back with similar errors to those below:

Warning: file() [function.file]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/absen/public_html/hs.php on line 29

Warning: file(http://hiscore.runescape.com/index_lite.ws?player=Zezima) [function.file]: failed to open stream: Inappropriate ioctl for device in /home/absen/public_html/hs.php on line 29

Warning: CURL error: "Couldn't resolve host 'hiscore.runescape.com'" in /home/absen/public_html/RSHiLib/RSHiLib_Core/library.php on line 121

Here is one of the many scripts that I tried. It is not obviously what I am going to use in the end, but it is useful for testing my connectivity.

PHP:
<?PHP
$user="absenm";

$txt=file_get_contents('http://hiscore.runescape.com/index_lite.ws?player='.$user);
$data = explode ("\n", $txt);
$looper=0;
$skillno=0;
while ($looper<30){
$type = explode(",",$data[$looper]);
$rank[$skillno]=$type[0];
$lvl[$skillno]=$type[1];
$xp[$skillno]=$type[2];
$looper++;
$skillno++;
}
?>

Please, any help would be greatly welcomed. I would rather not have to request the expert level php security level from x10hosting as I am not all that framiliar with php to begin with. But retrieval of this data from Runescape is very important to the future design of my website.
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
This is the second topic on this issue, please use the search function before posting. My solution to this is the code
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);
instead of
PHP:
@$hiscoredata = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user");

Note: the @ before the line makes it silent in case of failure (if a user is not found, you get a 404, which will cause a php error unless you have put the @ there or have set some option in the php.ini. check ($hiscoredata == null) if you want to know about failure)
 
Last edited:

absenm

New Member
Messages
16
Reaction score
0
Points
0
I did search the forums for this issue. I did find what you said before. I did read what you just suggested. I did perform what you suggested. It did not work. That is why I posted my much much more detailed question. I posted my question looking for a another answer or a modification to what you said. When I remove the @ I get the same errors I was getting before. Using your suggestion I get the following error (which is the same one the person you answered before got):

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 /home/absen/public_html/scores.php on line 13

You can see it for yourself at http://runethoughts.x10hosting.com/scores.php.
And this link will show you that I am listed on the hiscore site http://hiscore.runescape.com/index_lite.ws?player='absenm'

I do appreshiate your taking time to answer our questions.

Edit:
The following is the script I used on the scores.php link posted above. As you can see, there should be no reason why I would get a not found issue.

PHP:
<?php
$user = "absenm";
$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);
?>
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
I've been trying to find a solution to this since I send you that pm, but I still got nothing... When I try to request my own stats (Marshian007), my script works (some other names too), but when I try other names (such as yours (Absenm)) I get errors trying to get the contents and 200's when I use get_headers() on it... Can you try to find out more about this too? 2 heads is better than one...
Edit:
I might have (accidently, as usual) got it!
Try this:
PHP:
<?php
$user = "Marshian007";
$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"
		. "\r\n"
	)
);
$context = stream_context_create($context_options);
$hiscoredata = file_get_contents("http://168.75.184.54", false, $context);
?>
 
Last edited:

absenm

New Member
Messages
16
Reaction score
0
Points
0
Wonderful!!!! Amazing. I can't believe all the work and research that was needed to simply draw in one silly file. And in the end, it was the use of quotation marks. Now the tedious coding to parse and display the info the way I want (and store it locally so I don't have to hit the runescape site too often).

Anyway, excellant work!


Please Close This Thread
 
Last edited:

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
Thread Closed
Glad to see your problem was fixed. :)
 
Status
Not open for further replies.
Top