PHP Curl Help Needed.

Hello All!!
First let me thank everyone here for the work they do. its a pleasure coming here knowing that not only will i get help on issues i cannot fix, but also learn so much more than i ever anticipated.

now that the wheels are greased, let me get to the issue i am having,
there is an external webpage that i need to access and pull the json data from and the first part works great but the second function not so much. I belive it has to do with the encoding of the page but not sure. perhaps you can help. The 2nd Function is the issue, if i go directly to the page in my browser i get the following output,

{"type":"success","message":"RESERVATION","data":{"gameId":"18014398524603924","userId":"2955061301311539815","invitePersona":null,"game":2048,"sourceGuid":"0","expirationTimeout":60,"personaId":"1059352942","voipAllowed":true,"platform":1,"role":1,"gameServer":null,"joinState":"JOINED_GAME"}}

but when i run my function i get no data back at all.
here is the header information from the link directly, perhaps this is some of why i am not getting data?

Response Headers:

Cache-Control:max-age=0, no-cache, no-store Connection:keep-alive Content-Encoding:gzip Content-Length:241 Content-Type:application/json Date:Fri, 23 Jun 2017 22:13:54 GMT Expires:Fri, 23 Jun 2017 22:13:54 GMT Pragma:no-cache Vary:Accept-Encoding X-Node:127.0.0.1

Request Headers:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding:gzip, deflate, sdch, br Accept-Language:en-US,en;q=0.8,it;q=0.6 Connection:keep-alive Cookie:ssoremember=1; beaker.session.id=f4ef2e0b3cc694044af7125cb6c6a0e2; utag_main=v_id:015cd428e6680068a37809f1699005073002506b00bd0$_sn:6$_ss:0$_st:1498257835902$_pn:5%3Bexp-session$ses_id:1498254418273%3Bexp-session; comcenter.flushedOk=1; comcenter.isInSync=1; __utma=22379560.1135856904.1498208070.1498208070.1498240655.2; __utmb=22379560.500.9.1498245879774; __utmc=22379560; __utmz=22379560.1498208070.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=22379560.|1=userid=1000529509095=1^4=Customer=BF4PREMIUM=1^31=Platform=PC=1 Host:battlelog.battlefield.com Referer:https://brassmonkeymilitia.com/svrseeder1.php Upgrade-Insecure-Requests:1 User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

here is my code (raw and ugly but it does somewhat work)
[php]<?php
function guid2gid($guid) {
$ch = curl_init();
$apiuri = ‘http://keeper.battlelog.com/snapshot/’.$guid.’’;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if(curl_exec($ch) === false){
echo curl_error($ch) . ‘
’;
}
$gdata = json_decode(curl_exec($ch), true);
curl_close($ch);
return $gdata;
}

function reservation($pid,$gid) {
$ch = curl_init();
$apiuri = ‘https://battlelog.battlefield.com/bf4/launcher/reserveslotbygameid/1/’.$pid.’/’.$gid.’/1/0/0’;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if(curl_exec($ch) === false){
echo curl_error($ch) . ‘
’;
}
$gdata = json_decode(curl_exec($ch), true);
curl_close($ch);
return $rdata;

}
if (!isset($_GET['pid'])) {
	$pid = "1059352942";
	$guid = "4342465b-681c-46ff-835c-f9b6b0f6ddeb";
	$gid = "18014398524603924";
}else{
	$pid = $_GET['pid'];
	$guid = $_GET['guid'];
	$gid = $gdata['snapshot']['gameId'];
}
$debug = 2;
$gdata = guid2gid($guid);
$rdata = reservation($pid,$gid);

	if($debug == 1){
		echo '<p><h3><a href="http://keeper.battlelog.com/snapshot/'.$guid.'">http://keeper.battlelog.com/snapshot/'.$guid.'</a></h3></p>';
		echo "<pre>";
		print_r($gdata);
		echo "</pre>";
	}else if ($debug == 2){
		echo '<p><h3><a href="https://battlelog.battlefield.com/bf4/launcher/reserveslotbygameid/1/'.$pid.'/'.$gid.'/1/0/0">https://battlelog.battlefield.com/bf4/launcher/reserveslotbygameid/1/'.$pid.'/'.$gid.'/1/0/0</a></h3></p>';
		echo "<pre>";
		print_r($rdata);
		echo "</pre>";
	}

?>
[/php]

My overall goal with this is to have a simple form that submits to itself 2 $_GET vars $pid and $guid, then it takes that guid and converts it into the $gid using the fist function, finally it takes that $gid and processes the reservation request and grabs the data so i can output whether it was successful or not.

NOTE all requests will fail for anyone testing the code as you have to be logged into battlelog and have your own personaID (pid) but even a failed request will send data Which would look like this:{"type":"error","message":"WRONG_USER","data":{}}

I am noticing that in the function reservation, you are assigning $gdata for the json_decode and returning $rdata, my results are:

/usr/bin/php7.0 /home/jessica/.PhpStorm2017.1/config/scratches/scratch_1.php

https://battlelog.battlefield.com/bf4/launcher/reserveslotbygameid/1/1059352942/18014398524603924/1/0/0


Process finished with exit code 0

Which may resolve your problem, not 100% sure.

Sponsor our Newsletter | Privacy Policy | Terms of Service