forum

phpsu! - simple script to fetch user data from the API

posted
Total Posts
6
Topic Starter
pixeldesu

phpsu! - a simple script to fetch user data from the API

Introduction

phpsu! is a simple (and short) php-script, serving the user with variables to display stats from the osu!API. I made it, because I had nothing to do, and I know some people who still use(d) explode(); to fetch the userdata from the sorta-styleless profile page and since it's only a set of variables it's very simple to use for beginners (or lazy people).

NOTICE: Badly written, but it works!

Usage

Set up the config
- $key: Insert your osu!API-key, generate one here!
- $mode: Select your playmode: 0 = osu!, 1 = Taiko, 2 = CtB, 3 = osu!mania
- $user -> $type: Insert the username or ID of the player, if you use the username use string, id if you use the user-id, in $type
Set up up your site to show the stats
just
include 'osu.conf.php';
Variables you can use
On the page with the included file, just write your text/code and add the following values:

$user_id - the User ID
$user_name - the Username
$user_level - Level
$user_accuracy - Accuracy
$country - Country (as ISO3166-1 alpha-2 country code)
$playcount - your Playcount
$score_ranked - Ranked Score
$score_total - Total Score
$pp_rank - Your PP-Rank
$pp_raw - PP-Count
$rank_ss - Count of SS Ranks
$rank_s - Count of S Ranks
$rank_a - Count of A Ranks
Genesis Rose
Not even a repeatable function?

<?php
// Config Page
$key = ''; // Your osu! Api key.
//Page can be used for further configuration


?>

<?php
//Functions page
include ('config.php');

function phpsu_user($mode, $user, $type)
{
global $key;

$return = json_decode(file_get_contents("http://osu.ppy.sh/api/get_user?k=$key&u=$user&type=$type&m=$mode"), true);
if (!empty($return)) {
return $return;
} else {
return false;
}
}
?>

<?php
//Test page
include ('functions.php');
if ($user = phpsu_user('mode', 'user', 'type')) {
foreach ($user as $stat => $value) {
echo "$stat is $value";
}
} else {
echo "Failed.";
}

?>
Topic Starter
pixeldesu

There wrote:

Not even a repeatable function?

pixeldesu wrote:

I made it, because I had nothing to do [...] Badly written...
You can pull a request, tho. Just like I said, I wrote this thing in...some minutes just to simplify that on the users end, nothing big :P
Repflez
I did this time ago: https://osu.ppy.sh/forum/t/141331

Only that I did it return an array instead of n variables, used cURL with a fallback on servers that have it disabled and cached the data for 6 hours by default. Badly written too!
XPJ38
No offense but I really don't get why people would use a library to make a simple file_get_contents() followed by a json_decode(). If somebody knows how to code in PHP, they most likely know how to use these functions.
Repflez

XPJ38 wrote:

No offense but I really don't get why people would use a library to make a simple file_get_contents() followed by a json_decode(). If somebody knows how to code in PHP, they most likely know how to use these functions.
OCD

(I'll add wiki support to mine when I remember to do it this week)
Please sign in to reply.

New reply