Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. function post($url = null, $params = null, $ref = null, $headers = null, $proxy = null) {
  2.  $ch = curl_init();
  3.  
  4.  curl_setopt($ch, CURLOPT_URL, $url);
  5.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6.  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  7.  curl_setopt($ch, CURLOPT_REFERER, $ref);
  8.  
  9.  if($headers) {
  10.   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  11.  }
  12.  
  13.  if($params) {
  14.   curl_setopt($ch, CURLOPT_POST, 1);
  15.   curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  16.  }
  17.  
  18.  if($proxy) {
  19.   curl_setopt($ch, CURLOPT_PROXY, $proxy);
  20.  }
  21.  
  22.  $result = curl_exec($ch);
  23.  
  24.  curl_close($ch);
  25.  
  26.  return $result;
  27. }
  28.  
  29. /*
  30. Запрос без параметров (GET)
  31. echo post('http://vk.com');
  32.  
  33. GET запрос
  34. echo post('http://vk.com?param1=value1&param2=value2');
  35.  
  36. POST запрос
  37. echo post('http://vk.com', 'param1=value1&param2=value2');
  38.  
  39. Сложный запрос:
  40. echo post('http://vk.com', 'param1=value1&param2=value2', 'http://google.ru', array(
  41.  'Content-type: text/plain',
  42.  'Content-length: 100'
  43. ), 'ip:port');
  44. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement