I just finished this code for getting some informations about a game.
<?php
$apik = 'API_KEY';
$versionurl = 'https://ddragon.leagueoflegends.com/realms/na.json';
function request($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$decode = json_decode($response);
return $decode;
}
function getChamps(){
$array = getChampsId();
$champsn = count($array['champs']);
$arrayb = array();
$i = 0;
do {
$arrayb[$i] = $array['champs'][$i]->id;
$i = $i+1;
} while ($i<=$champsn-1);
$i = 0;
do {
echo getChampsNames($arrayb[$i]);
$i = $i+1;
} while ($i<=$champsn-1);
}
function getChampsId() {
global $apik;
$url = 'https://euw.api.pvp.net/api/lol/euw/v1.2/champion?freeToPlay=true&api_key='.$apik;
$req = request($url);
$array = array();
$array['champs'] = $req->champions;
return $array;
}
function getChampsNames($id) {
global $apik;
$ver = getVers('champion');
$url = 'https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/'.$id.'?locale=en_US&version='.$ver.'&champData=all&api_key='.$apik;
$req = request($url);
$array = array();
$array = $req->name;
return $array;
}
function getVers($obj){
$url = 'https://ddragon.leagueoflegends.com/realms/na.json';
$req = request($url);
$array = array();
$array = $req->n->$obj;
return $array;
}
?>
And to call:
getChamps();
The problem is that the website take like 30/40 (?) second to load.. why? I think there are too many curls? But I don't know any other method to do this, you have got some solution?