PDA

View Full Version : [Pension] PHP 'Get Habbo Join Date' Script



Plucked
06-04-2012, 09:05 PM
Right, so i've been attempting to get more knowledge of php, so I decided to code a basic little script which gets the join date of any given Habbo.com member. In order for this to work, the Habbo who's join date you want to get must have their profile public.

Live demo:
http://loduz.in/HabboJoinDate.php?habbo=INSERTNAMEHERE

PHP Code:

<?php

######################################
## PHP 'Get Habbo Join Date' Script ##
## Created by Pension (Robbie) ##
######################################

$habbo = $_GET['habbo'];

function getJoinDate($habbo)
{
$link = file_get_contents('http://www.habbo.com/home/'.$habbo);

$date = explode('<div class="birthday date">', $link);
$date = explode('</div>', $date[1]);
$date = trim($date[0]);

return $date;
}

echo '<b>Member since:</b><br />'.getJoinDate($habbo);
?>

It's kinda pointless, but I guess it *could* potentially be useful. Please rate/slate as much as you like :)

GoldenMerc
06-04-2012, 09:18 PM
Could be useful for someone, not too shabby ether +rep

Plucked
06-04-2012, 09:21 PM
Could be useful for someone, not too shabby ether +repCheers dude, I'm starting out with basic things but I have big ambitions, aha!

N!ck
07-04-2012, 01:02 AM
Pretty nice for somebody starting out. I would have used a preg_match to find the data in the HTML. Something like this (untested):


<?php

######################################
## PHP 'Get Habbo Join Date' Script ##
## Created by Pension (Robbie) ##
######################################

$habbo = $_GET['habbo'];

function getJoinDate($habbo)
{
$link = file_get_contents('http://www.habbo.com/home/'.$habbo);

preg_match('#<div class="birthday date">(.*?)</div>#s', $link, $date);
$date = trim($date[1]);

return $date;
}

echo '<b>Member since:</b><br />'.getJoinDate($habbo);
?>

This sort of thing is a nice introduction to regex, which I don't know much about myself, but enough to get by. http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

You may also consider using cURL to get web resources rather than file_get_contents. In this simple case it's more effort than it's worth, but cURL has a slight performance boost for getting web pages and has MANY features and lots of functionality http://www.php.net/manual/en/ref.curl.php for doing more advanced stuff.

Plucked
07-04-2012, 12:49 PM
Pretty nice for somebody starting out. I would have used a preg_match to find the data in the HTML. Something like this (untested):


<?php

######################################
## PHP 'Get Habbo Join Date' Script ##
## Created by Pension (Robbie) ##
######################################

$habbo = $_GET['habbo'];

function getJoinDate($habbo)
{
$link = file_get_contents('http://www.habbo.com/home/'.$habbo);

preg_match('#<div class="birthday date">(.*?)</div>#s', $link, $date);
$date = trim($date[1]);

return $date;
}

echo '<b>Member since:</b><br />'.getJoinDate($habbo);
?>

This sort of thing is a nice introduction to regex, which I don't know much about myself, but enough to get by. http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

You may also consider using cURL to get web resources rather than file_get_contents. In this simple case it's more effort than it's worth, but cURL has a slight performance boost for getting web pages and has MANY features and lots of functionality http://www.php.net/manual/en/ref.curl.php for doing more advanced stuff.Thanks for that, I'm going to take a look. +rep

Want to hide these adverts? Register an account for free!