Skip to content

Instantly share code, notes, and snippets.

@vvscode
Created August 9, 2014 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vvscode/1afec1a191514977003b to your computer and use it in GitHub Desktop.
Save vvscode/1afec1a191514977003b to your computer and use it in GitHub Desktop.
Curl: wrapper-functions
<?php
// инициализирует курл
// возвращает сессию курла
function curl_ini(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR,realpath(".").'/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE,realpath(".").'/tmp/cookies.txt');
curl_setopt ($ch, CURLOPT_USERAGENT, "Opera/9.52 (Windows NT 5.1; U; en)");
curl_setopt($ch,CURLOPT_VERBOSE,1);
return $ch;
}
// загрузка с помощью курла
function get_file_by_curl($url,$reffer=""){
$ch=curl_ini();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER,$reffer);
$result=curl_exec ($ch);
return $result;
}
// отправка POST запроса
// $url - куда
//$reffer - откуда
// $post - сам запрос
function send_POST($url,$reffer,$post){
$ch=curl_ini();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER,$reffer);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment