- Code: Select all
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wg\index.php on line 14
Notice: Undefined variable: id in C:\xampp\htdocs\wg\index.php on line 23
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wg\index.php on line 26
this code does not work
- Code: Select all
<?php
//Идентификатор приложения (Application_id), регистрация приложения https://ru.wargaming.net/developers/applications/
$appid = "demo";
//Тело скрипта
if(isset($_POST['nick']))
{
$nick = $_POST['nick'];
//Получение account_id (метод account/list)
$urlID = "https://api.worldoftanks.ru/wot/account/list/?application_id=$appid&search=$nick&limit=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $urlID);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$resultID = json_decode(curl_exec($curl), true);
foreach($resultID['data'] as $key => $value) {
/* Определяем account_id
Значение всех параметров можно изучить в документации к методу account/list
https://ru.wargaming.net/developers/api_reference/wot/account/list/
*/
$id = $value['account_id'];
}
//Получение общей статистики по боям (метод account/info)
$urlStat = "https://api.worldoftanks.ru/wot/account/info/?application_id=$appid&account_id=$id";
curl_setopt($curl, CURLOPT_URL, $urlStat);
$resultStat = json_decode(curl_exec($curl), true);
foreach($resultStat['data'] as $key => $valueInfo){
/* Определяем общее количество побед
Значение всех параметров можно изучить в документации к методу account/info
https://ru.wargaming.net/developers/api_reference/wot/account/info/
*/
$wins = $valueInfo['statistics']['all']['wins'];
curl_close($curl);
echo "<b>AccountID:</b> $id <br />
<b>Wins:</b> $wins";
}
}
?>
<p><form method="post">Nick <input name="nick" type="text"><input type="submit" value="Check!"></form></p>