title: Mixing 2 cURL requests
body: <p>This first snippet retrieves data from an API, json_decode(s) it and prints some data I choose:</p>
  
  <pre><code>&lt;?php
  $data=array('players'=&gt;array(),'opt'=&gt;array());
  
  // List of players
  $data['players'][]='multiforme';
  
  // List of options
  $data['opt']['clear']=true;
  $data['opt']['global']=true;
  $data['opt']['rank']=true;
  $data['opt']['scores']=true;
  $data['opt']['imgInfo']=true;
  $data['opt']['urls']=true;
  $data['opt']['lastseen']=true;
  
  // Platform can be pc, 360, ps3
  $platform='pc';
  
  // Convert lists to JSON
  $postdata=array();
  $postdata['players']=json_encode($data['players']);
  $postdata['opt']=json_encode($data['opt']);
  
  // Run POST Request via CURL
  $c=curl_init('http://api.bf3stats.com/'.$platform.'/playerlist/');
  curl_setopt($c,CURLOPT_HEADER,false);
  curl_setopt($c,CURLOPT_POST,true);
  curl_setopt($c,CURLOPT_USERAGENT,'BF3StatsAPI/0.1');
  curl_setopt($c,CURLOPT_HTTPHEADER,array('Expect:'));
  curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
  curl_setopt($c,CURLOPT_POSTFIELDS,$postdata);
  $data=curl_exec($c);
  $statuscode=curl_getinfo($c,CURLINFO_HTTP_CODE);
  curl_close($c);
  
  if($statuscode==200) {
      // Decode JSON Data
      $data=json_decode($data,true);
  
      // Print data for debugging
      echo '&lt;pre&gt;';
  
  // print list of players with rank and score
      foreach($data['list'] as $d) {
          $stats=$d['stats'];
          echo '&lt;a href="http://battlelog.battlefield.com/bf3/soldier/multiforme/stats/883167655/"&gt;' . $d['name'].'&lt;/a&gt;'." | Livello &lt;img src=\"http://www.teamkillerhunters.com/bf3stats/stylesheets/images/".$stats['rank']['img_tiny']."\" title=\"".$stats['rank']['nr']."\" alt=\"".$stats['rank']['nr']."\"/&gt; | Punteggio: ".$stats['scores']['score']. " | Ultima partita: ".htmlentities(strftime('%e %B %Y alle %R', $d['date_lastseen']));
      }
      echo '&lt;/pre&gt;';
      // ... now you use $data to do whatever
  
  } else {
      echo "BF3 Stats API error status: ".$statuscode;
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>This other snippet authenticates with a key and send the command to update the data in the APIs:</p>
  
  <pre><code>&lt;?php
  
  // API access data
  $BF3APIIdent='multiforme';
  $BF3APIKey='XXXXXXXX';
  
  // Platform can be pc, 360, ps3
  $platform='pc';
  
  
  $data=updatePlayer($platform,'multiforme');
  #$data=lookupPlayer($platform,'multiforme');
  
  #$data=setupClientKey('testident','For testing');
  #$data=getClientKey('R2DGATJ9ek');
  
  
  // Print data for debugging
  echo '&lt;pre&gt;';
  print_r($data);
  echo '&lt;/pre&gt;';
  
  
  function setupClientKey($clientident=null,$name=null) {
      global $BF3APIIdent;
      $data=array();
      $data['ident']=$BF3APIIdent;
      $data['time']=time();
      $data['clientident']=$clientident;
      $data['name']=$name;
      return getAPIDataSigned('setupkey','global',$data);
  }
  
  function getClientKey($clientident) {
      global $BF3APIIdent;
      $data=array();
      $data['ident']=$BF3APIIdent;
      $data['time']=time();
      $data['clientident']=$clientident;
      return getAPIDataSigned('getkey','global',$data);
  }
  
  function lookupPlayer($platform,$name) {
      global $BF3APIIdent;
      $data=array();
      $data['ident']=$BF3APIIdent;
      $data['time']=time();
      $data['player']=$name;
      return getAPIDataSigned('playerlookup',$platform,$data);
  }
  
  
  function updatePlayer($platform,$name) {
      global $BF3APIIdent;
      $data=array();
      $data['ident']=$BF3APIIdent;
      $data['time']=time();
      $data['player']=$name;
      return getAPIDataSigned('playerupdate',$platform,$data);
  }
  
  
  function getAPIDataSigned($type,$platform,$data) {
      global $BF3APIKey;
      // Convert data to JSON
      $urlbase64=array('+'=&gt;'-','/'=&gt;'_','='=&gt;'');
      $data=strtr(base64_encode(json_encode($data)),$urlbase64);
  
      $postdata=array();
      $postdata['data']=$data;
      $postdata['sig']=strtr(base64_encode(hash_hmac('sha256',$data,$BF3APIKey,true)),$urlbase64);
  
      // Run POST Request via CURL
      $c=curl_init('http://api.bf3stats.com/'.$platform.'/'.$type.'/');
      curl_setopt($c,CURLOPT_HEADER,false);
      curl_setopt($c,CURLOPT_POST,true);
      curl_setopt($c,CURLOPT_USERAGENT,'BF3StatsAPI/0.1');
      curl_setopt($c,CURLOPT_HTTPHEADER,array('Expect:'));
      curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
      curl_setopt($c,CURLOPT_POSTFIELDS,$postdata);
      $data=curl_exec($c);
      $statuscode=curl_getinfo($c,CURLINFO_HTTP_CODE);
      curl_close($c);
  
      if($statuscode==200) {
          // Decode JSON Data
          $data=json_decode($data,true);
          return $data;
  
      } else {
          echo "BF3 Stats API error status: ".$statuscode;
          return false;
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>How can I mix these 2 functions so I have:
  First updates the API (second function), then retrieves $data and with the foreach I extrapolate entries from JSON.</p>