Created
August 9, 2014 07:33
-
-
Save vvscode/1afec1a191514977003b to your computer and use it in GitHub Desktop.
Curl: wrapper-functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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