Jump to content

Please help me with this.


Maciek20

Recommended Posts

I would like to have a script on my website about MMORPG TIBIA. If someone could write script which will show on my website information if player is online/offline I would be thankful.

 

Script would take information about player who I would to see if hes online/offline on my page from there:

 

http://www.tibia.com/community/?subtopic=whoisonline&world=Mythera

 

 

Thanks for help.

Link to comment
https://forums.phpfreaks.com/topic/94067-please-help-me-with-this/
Share on other sites

Since I like some exercise now and then, I wrote it for you. It's pretty simple: You load in the page in question, and check whether the given player name is present or not.

 

<?php
$playerName = 'Name here';
$world = 'Mythera';
$url = 'http://www.tibia.com/community/?subtopic=whoisonline&world='.$world;
$pageString = file_get_contents($url);
if (strpos($pageString, $playerName) !== false) {
	echo $playerName, ' is online in ', $world, '.';
} else {
	echo $playerName, ' is offline in ', $world, '.';
}
?>

 

Edit: Be aware that the page we're loading is around 241 KB in size. May take a little while.

Oops, realized I made some mistakes, this should work as intended:

 

<?php
$playerName = 'Name here';
$playerName = str_replace(' ', '&#160;', $playerName);
$world = 'Mythera';
$url = 'http://www.tibia.com/community/?subtopic=whoisonline&world='.$world;
$pageString = file_get_contents($url);
if (strpos($pageString, '">'.$playerName.'</A>') !== false) {
	echo $playerName, ' is online in ', $world, '.';
} else {
	echo $playerName, ' is offline in ', $world, '.';
}
?>

 

Edit: Argh! The forum is wrecking my ampersand on line 2 in the code. It should read

 

$playerName = str_replace(' ', '&#160;', $playerName);

Oops, realized I made some mistakes, this should work as intended:

 

<?php
$playerName = 'Name here';
$playerName = str_replace(' ', '\ ', $playerName);
$world = 'Mythera';
$url = 'http://www.tibia.com/community/?subtopic=whoisonline&world='.$world;
$pageString = file_get_contents($url);
if (strpos($pageString, '">'.$playerName.'</A>') !== false) {
	echo $playerName, ' is online in ', $world, '.';
} else {
	echo $playerName, ' is offline in ', $world, '.';
}
?>

 

Ya really shouldn't just make scripts for people who can't be bothered to do it themselves or pay a freelance, because then other people will ask assuming that we will help do the same for them etc.

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.