SRL Archive - NOTA

server side php Question.


Laimonas171

2009-07-22 17:26:23

i got php code which one perfectly works on localhost (wampserver) but then i put same *.php into server it doesn't work.
in local host i write http://localhost/index.php?world=10 it shows perfectly, $time value (code gets players amount and calculate $time formula)
in server side http://myaddress/index.php?world=10 it always gets 2000 amount of players, and calculates same time 750 on this script because it using always "full" amount of players (2k).
an ideas why is it?
[PHP]
<?php <?php $world = $_GET["world"];
$data = file_get_contents("http://www.runescape.com/slu.ws");
$search = strstr($data, "World {$world}");
$players = substr($search, 21 + strlen($world), 4);
$players = trim($players);
$players = (is_numeric($players) ? $players : 2000);
$a = 1500;
$b = 3;
$c = 8;
$x = 60;
$time = $a - ( $b * $players / $c);

echo round($time);
?>[/PHP]

Floor66

2009-07-22 17:30:23

Sec, let me test on my webserver (not localhost).

Da 0wner

2009-07-22 17:40:01

Two php opening tags? Might not be the problem though :p.

Edit: And I just tested on localhost, outputted 750.

Floor66

2009-07-22 17:45:14

BIG EDIT:
The whole mistake was because of the last one (see old post)! The user would fill in ?world=5, world 51 would be found, but strlen($world) would still be 1.
[php]
<?php
$world = $_GET["world"];
$data = file_get_contents("http://www.runescape.com/slu.ws");
$search = strstr($data, "World {$world}</a>");
$players = trim(substr($search, 21 + strlen($world), 4));
if (empty($players)) //Just as failsafe for full worlds.
{
$players = 2000;
}
$time = round(1500 - ( 3 * $players / 8));

echo "<strong>You picked world {$world}, on this world there are {$players} players, so you have to wait <span id=\"scar_value\">{$time}</span> seconds for the ore to respawn.</strong>";
//I just made a little explanation with it.
?>
[/php]

That works with every world!
See the old post for the SCAR part. That stays the same.

Old post:
From: OldPost
Nope that's not it. I found what it is.
Some of the $player values had ">123", the ">" added from a HTML tag.
[php]
<?php
$world = $_GET["world"];
$data = file_get_contents("http://www.runescape.com/slu.ws");
$search = strstr($data, "World {$world}");
$players = str_replace(">", "", trim(substr($search, 21 + strlen($world), 4)));
$time = round(1500 - ( 3 * $players / 8));

echo "<strong>You picked world {$world}, on this world there are {$players} players, so you have to wait <span id=\"scar_value\">{$time}</span> seconds for the ore to respawn.</strong>";
//I just made a little explanation with it. LOOK DOWN, THERE'S MORE!
?>
[/php]

If you want to get the value in SCAR just do

Var
Page : String;
Time : Integer;

Page := GetPage('blabla');
Time := StrToInt(Between('<span id="scar_value">', '</span>', Page));

BUT!
There is another weakness in the script.
If, for example you fill in ?world=5, and it finds world 51 first, it will get the user count of world 51, not world 5.
This is easily fixed by doing this:
[php]
$search = strstr($data, "World {$world}</a>"); //The </a> is just the closing tag of the link they add to each world.
[/php]

So that makes:
[php]
<?php
$world = $_GET["world"];
$data = file_get_contents("http://www.runescape.com/slu.ws");
$search = strstr($data, "World {$world}</a>");
$players = str_replace(">", "", (trim(substr($search, 21 + strlen($world), 4))));
$time = round(1500 - ( 3 * $players / 8));

echo "<strong>You picked world {$world}, on this world there are {$players} players, so you have to wait <span id=\"scar_value\">{$time}</span> seconds for the ore to respawn.</strong>";
//I just made a little explanation with it.
?>
[/php]

Laimonas171

2009-07-22 21:07:39

From: Floor66
BIG EDIT:
The whole mistake was because of the last one (see old post)! The user would fill in ?world=5, world 51 would be found, but strlen($world) would still be 1.
[php]
<?php
$world = $_GET["world"];
$data = file_get_contents("http://www.runescape.com/slu.ws");
$search = strstr($data, "World {$world}</a>");
$players = trim(substr($search, 21 + strlen($world), 4));
if (empty($players)) //Just as failsafe for full worlds.
{
$players = 2000;
}
$time = round(1500 - ( 3 * $players / 8));

echo "<strong>You picked world {$world}, on this world there are {$players} players, so you have to wait <span id=\"scar_value\">{$time}</span> seconds for the ore to respawn.</strong>";
//I just made a little explanation with it.
?>
[/php]

That works with every world!
See the old post for the SCAR part. That stays the same.

Old post:

i'm not at home but then i get back i will test your corection ty. :)
btw i'm makeing client Beta version. for mining, without autoing, just some timer and other features , i'll release beta if all php's works nicely today

Laimonas171

2009-07-22 23:32:36

Your scrip show 1500 all time idk what is wrong and about 5 > 51 so need to use this adress http://www.runescape.com/slu.ws?order=WMLPA this one goes 1,2,3,…

Floor66

2009-07-23 00:39:20

I PMed u back.