How to get steam level and make a check if someone has at least steam level 2

北战南征 提交于 2019-12-23 04:58:33

问题


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.')));
    }   
 ?>

回答1:


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.')));
  }
 ?>


来源:https://stackoverflow.com/questions/51549291/how-to-get-steam-level-and-make-a-check-if-someone-has-at-least-steam-level-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!