Jump to content

Follow on to my earlier FP post


prime

Recommended Posts

After help from here earlier I've managed to put together the folowing script

 

<html><head></head><body bgcolor="black">


<?php /*
$name = $_POST['rsname'];
$url = "http://hiscore.runescape.com/index_lite.ws?player=$name" ;
$fp = @fopen ($url, 'r') or die ('<font color="red"><center>ERROR</font><br/><font color="white">cannot access highscores</center></font>');
while ($read = fgetcsv ($fp, 1024)) {
  print_r($read);
}
fclose($fp); 
*/ ?>

<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
$name = $_POST['rsname'];
$url = "http://hiscore.runescape.com/index_lite.ws?player=$name" ;
$fp = @fopen ($url, 'r') or die ('<font color="red"><center>ERROR</font><br/><font color="white">cannot access highscores</center></font>');
$read = (fgetcsv($fp, 1024));
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>

<table border="1" bordercolor="red" align="center">><tr>

<td><font color="orange" size="1"><b><center>Skill</center></b></font></td>
<td><font color="orange" size="1"><b><center>Level</center></b></font></td>
<td><font color="orange" size="1"><b><center>Rank</center></b></font></td>
<td><font color="orange" size="1"><b><center>XP</center></b></font></td>



</tr><td><font color="orange" size="1">
Overall:<br/>
Attack:<br/>
Defence:<br/>
Strength:<br/>
Hitpoints:<br/>
Ranged:<br/>
Prayer:<br/>
Magic:<br/>
Cooking:<br/>
Woodcutting:<br/>
Fletching:<br/>
Fishing:<br/>
Firemaking:<br/>
Crafting:<br/>
Smithing:<br/>
Mining:<br/>
Herblore:<br/>
Agility:<br/>
Thieving:<br/>
Slayer:<br/>
Farming:<br/>
Runecraft:<br/>
Hunter:<br/>
Construction:<br/>
</font></td>


<td valign="top"><?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo "<font color='orange' size='1'> $read[1] </font><br/>";
?>
<?php

while ($read = fgetcsv($fp, 1024)) {
  echo "<font color='orange' size='1'> $read[1] </font><br/>";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?></td>

<?php
fclose($fp);
?>



<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
$name = $_POST['rsname'];
$url = "http://hiscore.runescape.com/index_lite.ws?player=$name" ;
$fp = @fopen ($url, 'r') or die ('<font color="red"><center>ERROR</font><br/><font color="white">cannot access highscores</center></font>');
$read = (fgetcsv($fp, 1024));
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>

<td valign="top"><?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo "<font color='orange' size='1'> $read[0] </font><br/>";
?>
<?php

while ($read = fgetcsv($fp, 1024)) {
  echo "<font color='orange' size='1'> $read[0] </font><br/>";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?></td>

<?php
fclose($fp);
?>

<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
$name = $_POST['rsname'];
$url = "http://hiscore.runescape.com/index_lite.ws?player=$name" ;
$fp = @fopen ($url, 'r') or die ('<font color="red"><center>ERROR</font><br/><font color="white">cannot access highscores</center></font>');
$read = (fgetcsv($fp, 1024));
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>

<td valign="top"><?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo "<font color='orange' size='1'> $read[2] </font><br/>";
?>
<?php

while ($read = fgetcsv($fp, 1024)) {
  echo "<font color='orange' size='1'> $read[2] </font><br/>";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
?></td>

<?php
fclose($fp);
?>


</tr></table></body></html>

 

But it does seem to be rather long, I've tried shrinking it down but that seems to break the code, So my question is there a more effient way of saying this code?

Link to comment
https://forums.phpfreaks.com/topic/64341-follow-on-to-my-earlier-fp-post/
Share on other sites

I've tried to break it down, but when I only have it read once, it returns a blank value, so not sure what I'm doing wrong.

 

and that backend is actualy new, there was a whole issue of people maijng stat sigs and such, and well jagex actualy tried to make anything that accesses their site like that illegal.

 

one of the world switcher authors tried to suggest a low bandwidth backend, and jagex replied saying that wasn't feasable.

 

after a month of trying to threaten everyone off, they released a low bandwidth backend like what I'm linking to....

So basically someone went 'we should do this!' and they shot him down... Then did it a month later.... Hahahaha

 

Anyway, I would try reading in the entire file instead of little pieces at a time and then I would break it down since that wouldn't be a big memory hit to do it that way and it's a bit easier....  Gimme a sec and I'll make an example.

thats pretty much what happened.......

 

and I'm fairly new to php and this took a lot of me playing around to get working as is, then only one of the arrays would lookup array[2] or whatever.

 

the only way I could get them all to read like that was to have a new read stream for each, not actualy sure what I was doing wrong

<html>
<head>

</head>

<body bgcolor="black">
<center>
<?php

$names = array(
'Overall:',
'Attack:',
'Defence:',
'Strength:',
'Hitpoints:',
'Ranged:',
'Prayer:',
'Magic:',
'Cooking:',
'Woodcutting:',
'Fletching:',
'Fishing:',
'Firemaking:',
'Crafting:',
'Smithing:',
'Mining:',
'Herblore:',
'Agility:',
'Thieving:',
'Slayer:',
'Farming:',
'Runecraft:',
'Hunter:',
'Construction:',
);

$name = (isset($_GET['rsname']) && strlen($_GET['rsname']) > 0) ? $_GET['rsname'] : null;

echo '<font style="color: white; font-size: 22px;">Runescape Hi-Scores</font><br /><br />';

if($name != null) {

$url = 'http://hiscore.runescape.com/index_lite.ws?player='.$name;

$handle = @fopen($url, 'rb');
if($handle) {
	echo '<font style="font-size: 22px; color: white;">'.$name.'</font><br /><br />';
	$contents = '';
	while (!feof($handle)) { //while the file end isnt reached
	$contents .= fread($handle, 8192);
	}

	$contents = explode("\n", $contents); //split the content at linebreaks and put it into array $contents

	$i = 0;

	foreach($contents as $v) {
		$e = explode(',', $v);
		$skills[$i]['rank'] = $e[0];
		$skills[$i]['level'] = $e[1];
		$skills[$i]['xp'] = $e[2];
		$i++;
	}
	echo '<table border="1" bordercolor="red" align="center">
<tr>
<td><font color="orange" size="1"><b><center>Skill</center></b></font></td>
<td><font color="orange" size="1"><b><center>Level</center></b></font></td>
<td><font color="orange" size="1"><b><center>Rank</center></b></font></td>
<td><font color="orange" size="1"><b><center>XP</center></b></font></td>
</tr>';

	foreach($skills as $k => $v) {
		echo '<tr>
<td><font color="orange" size="1"><b>'.$names[$k].'</b></font></td>
<td><font color="orange" size="1"><b>'.$v['level'].'</b></font></td>
<td><font color="orange" size="1"><b>'.$v['rank'].'</b></font></td>
<td><font color="orange" size="1"><b>'.$v['xp'].'</b></font></td>
</tr>';
	}
	echo '</table>';
}
else {
	echo '<font color="white">Unable to find the user or open the page.  Please make sure the username is correct or try again later.</font>';
}
}

if($name == null) {
	echo '<br /><font color="white">Please enter a username to search for.</font>';
}
echo '<form action="" method="GET">';
echo '<input type="text" name="rsname" value="'.$name.'" /><br /><br />';
echo '<input type="submit" value="Search!" />';

?>
</center>
</body>
</html>

 

That should work just fine....

 

Got kinda distracted with it or it wouldn't have taken 40 minutes... hehe

 

Anyway, I made a form for it since I didn't see one before, and now it uses $_GET instead of POST since I don't like POST in situations like this one (personal preference thing).

 

I'm kinda distracted at the moment, but if you need me to explain anything, just ask and I'll try later.

the form I made was pretty basic since it just needed to collect and pass a single variable to the php script here's code I used

 

<form target="skills" action="skilllookup.php" method="post"><input type="text" name="rsname" />
<input type="submit" value="Stats Lookup" /></form>

 

thanks for the Huge help :-D

No problem ;p.

 

I just realized when I relooked over the code that you could easily splice the two foreach's together, but it shouldn't make much of a difference.

 

Also, you'll want to check for the place being -1 or something since that looks kind of odd when it's output as -1.

Wow that works great, thank you :-D

 

I've modified the script to being

 

<html><head>

<?php //include styles and javascript files
include("../../../style_java_include.inc");
?>

</head><body bgcolor="black">

<?php

$names = array(
'Overall:',
'Attack:',
'Defence:',
'Strength:',
'Hitpoints:',
'Ranged:',
'Prayer:',
'Magic:',
'Cooking:',
'Woodcutting:',
'Fletching:',
'Fishing:',
'Firemaking:',
'Crafting:',
'Smithing:',
'Mining:',
'Herblore:',
'Agility:',
'Thieving:',
'Slayer:',
'Farming:',
'Runecraft:',
'Hunter:',
'Construction:',
);

$name = (isset($_POST['rsname']) && strlen($_POST['rsname']) > 0) ? $_POST['rsname'] : null;

if($name != null) {

$url = 'http://hiscore.runescape.com/index_lite.ws?player='.$name;

$handle = @fopen($url, 'rb');
if($handle) {
	$contents = '';
	while (!feof($handle)) { //while the file end isnt reached
	$contents .= fread($handle, 8192);
	}

	$contents = explode("\n", $contents); //split the content at linebreaks and put it into array $contents

	$i = 0;

	foreach($contents as $v) {
		$e = explode(',', $v);
		$skills[$i]['rank'] = $e[0];
		$skills[$i]['level'] = $e[1];
		$skills[$i]['xp'] = $e[2];
		$i++;
	}
	echo '<table border="0" bordercolor="red" align="center">
<tr>
<td width="60"><b class="otkhead">Skill</b></td>
<td width="40"><b class="otkhead">Level</b></td>
<td width="40"><b class="otkhead">Rank</b></td>
<td width="30"<b class="otkhead">XP</b></td>
</tr>';

	foreach($skills as $k => $v) {
		echo '<tr>
<td><b class="otkskilltitle">'.$names[$k].'</b></td>
<td><b class="otkskills">'.$v['level'].'</b></td>
<td><b class="otkskills">'.$v['rank'].'</b></td>
<td><b class="otkskills">'.$v['xp'].'</b></td>
</tr>';
	}
	echo '</table>';
}
else {
	echo '<font color="white">Unable to find the user or open the page.  Please make sure the username is correct or try again later.</font>';
}
}

?>

</body></html>

 

Since I'm getting the variable from econdary form here's a screenshot of what the full prog looks like so far:

 

prktp2.png

 

The bit I'm working on atm is a javascript or ajax mouseover so that when the mouse goes over a skill it has a mouseover display of how much xp to the next level of that skill.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.