Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function call($vars){
- //* generic Curl method to call the API server
- //* gets cookie from client, sets it as a temp file for the curl cookie jar
- //* makes request on behalf of the remote client and then saves the cookie back to the client
- //open temp file
- $tmpFileName = 'cookie_'.(microtime(true)*100).rand(100,999);
- $tmpFileHandle = fopen($this->tempDir.$tmpFileName, 'w') or die("can't open cookie cache file");
- fwrite($tmpFileHandle, base64_decode($_COOKIE['remoteID']));
- fclose($tmpFileHandle);
- //build var string
- $first = true;
- foreach($vars as $varName => $var){
- if($first){
- $getVars .= "?";
- }else{
- $getVars .= '&';
- }
- $getVars .= urlencode($varName).'='.urlencode($var);
- $first = false;
- }
- //call remote server
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->apiServerURL."/".$this->params['section']."/".$this->params['method'].$getVars);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $this->tempDir.$tmpFileName);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $this->tempDir.$tmpFileName);
- $output = json_decode(curl_exec($ch));
- $info = curl_getinfo($ch);
- curl_close($ch);
- unset($ch); // run in to a problem with this a few times
- //set cookie on client
- $tmpFileHandle = fopen($this->tempDir.$tmpFileName, 'rb') or die("can't open cookie cache file");
- $_COOKIE['remoteID'] = base64_encode(fread($tmpFileHandle, filesize($this->tempDir.$tmpFileName)));
- fclose($tmpFileHandle);
- return $output;
- }
Add Comment
Please, Sign In to add comment