Skip to content

Instantly share code, notes, and snippets.

@Noahii
Created October 10, 2013 15:44
Show Gist options
  • Save Noahii/6920557 to your computer and use it in GitHub Desktop.
Save Noahii/6920557 to your computer and use it in GitHub Desktop.
BF4 battlelog JSON stats thing for PHP
<?php
//Self Explanatory \
$postchars = http_build_query(array(
'redirect' => '',
'email' => '[email protected]',
'password' => 'wdfaqwgaf',
'submit' => 'Log+in'
), '', '&');
$ckfile = tempnam ("/tmp", "COOKIES");
$ch = curl_init('https://battlelog.battlefield.com/bf4/gate/login/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Expect:',
'User-Agent: ' . 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0',
'Accept: */*',
'Accept-Language: en-us,en;q=0.5',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postchars);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
curl_close($ch);
//--------------------------------------------------------------\ user ID / http://noahi.me/ongxy
$ch = curl_init("http://battlelog.battlefield.com/bf4/indexstats/349400632/1/?stats=1");
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Expect:',
'User-Agent: ' . 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0',
'Accept: */*',
'Accept-Language: en-us,en;q=0.5',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'X-Requested-With: XMLHttpRequest',
'X-AjaxNavigation: 1'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data);
//Layout etc http://noahi.me/ynfap
$stats = $json['data']['generalPersonaStats'];
echo $stats['skill'] . " skill</br>";
echo $stats['kdRatio'] . " kdRatio</br>";
echo $stats['kills'] . " kills</br>";
echo $stats['score'] . " score</br>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment