I’m modifying a script where I want to get some server stats, where I’ve put my server key as one of the variables. I fear that the variable can’t have minus within them. Is that true?
See line 3.
// Convert lists to JSON
$postdata=array();
$postdata['id']="534f7035-cef8-48aa-b233-8d44a0956e68";
// Run POST Request via CURL
$c2=curl_init('http://api.bf3stats.com/'.$platform.'/server/');
curl_setopt($c2,CURLOPT_HEADER,false);
curl_setopt($c2,CURLOPT_POST,true);
curl_setopt($c2,CURLOPT_USERAGENT,'BF3StatsAPI/0.1');
curl_setopt($c2,CURLOPT_HTTPHEADER,array('Expect:'));
curl_setopt($c2,CURLOPT_RETURNTRANSFER,true);
curl_setopt($c2,CURLOPT_POSTFIELDS,$postdata);
$id=curl_exec($c2);
$statuscode=curl_getinfo($c2,CURLINFO_HTTP_CODE);
curl_close($c2);
if($statuscode==200) {
// Decode JSON Data
$id=json_decode($id,true);
} else {
echo "BF3 Stats API error status: ".$statuscode;
}
Your code will work fine, however; since you’re not parsing any variables in the string, you might as well use single quotes (
') instead of double quotes ("). The micro-optimization factor of it makes virtually no difference, but it’ll ensure you never have any accidental results after modifying the string.