Advertisement
thexiv

Untitled

Mar 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1.  
  2.     public function prepare_curl_handle($server_url, $fields, $token){
  3.  
  4.         $field = [];  
  5.         foreach ($fields as $k => $v)
  6.             $field = array_merge($field, array($k => $v));
  7.         $field = array_merge($field, array("token" => $token));
  8.         $handle = curl_init($server_url);
  9.         $user_agent=$_SERVER['HTTP_USER_AGENT'];
  10.  
  11.         curl_setopt($handle, CURLOPT_TIMEOUT, 20);
  12.         curl_setopt($handle, CURLOPT_URL, $server_url);
  13.         curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  14.         curl_setopt($handle, CURLOPT_POST, 1);
  15.         curl_setopt($handle, CURLOPT_FOLLOWLOCATION,true);
  16.         curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($field));
  17.         curl_setopt($handle, CURLOPT_BINARYTRANSFER, true);
  18.         curl_setopt($handle, CURLOPT_ENCODING, "");
  19.         curl_setopt($handle, CURLOPT_USERAGENT, $user_agent);
  20.        
  21.         $len = strlen(json_encode($field));
  22.         curl_setopt($handle, CURLOPT_HTTPHEADER, array(                                                                  
  23.             'Content-Type' => 'application/json',
  24.             'Content-Length' => $len
  25.             )
  26.         );
  27.  
  28.         $reg = curl_exec($handle);
  29.         echo json_encode($reg);
  30.         return $handle;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement