Page MenuHomePhabricator
Authored By
stwalkerster
Apr 8 2016, 7:43 PM
Size
870 B
Referenced Files
None
Subscribers
None
<?php
ini_set("user_agent", 'ExampleProject/0.0 (wikimedia@stwalkerster.co.uk)');
// bomb out early if no username specified
if (!isset($_GET['username'])) {
echo "No username specified!";
return;
}
// get the API result as a JSON string
$json = file_get_contents("https://en.wikipedia.org/w/api.php?action=query&format=json&list=users&usprop=editcount&ususers=" . htmlspecialchars($_GET["username"]));
// decode the JSON in to an associative array (second parameter enforces array rather than object)
$conf = json_decode($json, true);
// Use isset() to check if something is set - that way you don't get PHP Notices
if (!isset($conf['query']['users']['0']) || isset($conf['query']['users']['0']['missing'])) {
echo "The user '" . htmlspecialchars($_GET["username"]) . "' does not exist.";
} else {
echo $conf['query']['users']['0']['editcount'];
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
277
Default Alt Text
(870 B)

Event Timeline