Reputation: 11
I've been thinking about this so much and made it but something is wrong I think in the code. Can you say me what's it? I'd appreciate it! :)
<?php
$link = file_get_contents("http://api.steampowered.com/IPlayerService/GetSteamLevel/v1/?
key=".$api_key."&steamid=".$user['steamid']);
$result = json_decode($link, true);
$_SESSION['steam_level'] = $result['response']['player_level'];
if(!$_SESSION['steam_level'] >=2 && $_SESSION['steam_level'] <=3000){
exit(json_encode(array('success'=>false, 'error'=>'You must have steam level 2 at least.')));
}
?>
Upvotes: 0
Views: 414
Reputation: 1411
There is a problem with your if statement. It appears the issue is with the !
(not) at the front of the first part of your if
statement. Essentially, you were looking at someone who was within the parameters of your first condition but with the addition of the !
was causing the whole statement to become false, thus not completing any of the actions within the if
statement. If you added an else
statement to your code it would have worked.
My code below, flipped it around. So essentially, my first statement is looking to see if the steam users level is between 2
and 3000
. If it is exit("success")
, if not, show your error message.
<?php
$link = file_get_contents("http://api.steampowered.com/IPlayerService/GetSteamLevel/v1/?
key=".$api_key."&steamid=".$user['steamid']);
$result = json_decode($link, true);
$_SESSION['steam_level'] = $result['response']['player_level'];
if($_SESSION['steam_level'] >= 2 && $_SESSION['steam_level'] <= 3000) {
exit("success");
} else {
exit(json_encode(array('success'=>false, 'error'=>'You must have steam level 2 at least.')));
}
?>
Upvotes: 1