Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. function post($url = null, $params = null) {
  2.  $ch = curl_init();
  3.  
  4.  curl_setopt($ch, CURLOPT_URL, $url);
  5.  curl_setopt($ch, CURLOPT_HEADER, 1);
  6.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7.  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  8.  
  9.  if(isset($params['params'])) {
  10.   curl_setopt($ch, CURLOPT_POST, 1);
  11.   curl_setopt($ch, CURLOPT_POSTFIELDS, $params['params']);
  12.  }
  13.  
  14.  if(isset($params['headers'])) {
  15.   curl_setopt($ch, CURLOPT_HTTPHEADER, $params['headers']);
  16.  }
  17.  
  18.  if(isset($params['cookies'])) {
  19.   curl_setopt($ch, CURLOPT_COOKIE, $params['cookies']);
  20.  }
  21.  
  22.  $result = curl_exec($ch);
  23.  
  24.  list($headers, $result) = explode("\r\n\r\n", $result, 4);
  25.  
  26.  preg_match_all('|Set-Cookie: (.*);|U', $headers, $parse_cookies);
  27.  
  28.  $cookies = implode(';', $parse_cookies[1]);
  29.  
  30.  curl_close($ch);
  31.  
  32.  return array('headers' => $headers, 'cookies' => $cookies, 'content' => $result);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement