0

Im getting json files from a site and i want it to find which ever one gets the file and use that one. Im using the $_GET Method too. There are 2 ways of getting the same file but they both require an id or a custom url from steam.

My url example: www.mysite.com?id=123123123

2 ways of getting json file:

How im decoding it:

$id = $_GET['id'];
$url = "http://steamcommunity.com/id/".$id."/inventory/json/730/2";
$content = file_get_contents($url);
$playerinfo = json_decode($content, true);
$InventoryStatus = $playerinfo['success'];
bbousq
  • 615
  • 1
  • 5
  • 13

1 Answers1

0

some ref

$id = $_GET['id'];
$handlers =array(
    'getByJson','getByDB','getBySomething'
);
$result = array('handler'=>'','data'=>'');

then call $handlers

foreach($handlers as $m){
    $methodResult = call_user_func($m,$id);
    if($methodResult !==false){
        $result = array('handler'=>$m, 'data' => $methodResult) ;
        break;
    }
}

handler something like this

function getByJson($id){
    $url = "http://steamcommunity.com/id/".$id."/inventory/json/730/2";
    $string = file_get_contents($url);
    $isJson =is_string($string) && is_object(json_decode($string)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
    if($isJson){
       $playerinfo = json_decode($content, true);
       return $playerinfo['success'];
    }

    return false;
}

function getByDB($id){
     // get $result

        if(condition){
            return $result
        }
        return false;

}

function getBySomething($id){
         // get $result

        if(condition){
            return $result
        }
        return false;
}
JOE LEE
  • 1,058
  • 1
  • 6
  • 6