Skip to content

Instantly share code, notes, and snippets.

@spacebit-official
Last active November 17, 2017 00:44
Show Gist options
  • Select an option

  • Save spacebit-official/831a7068f46bba1b69e94800581381c7 to your computer and use it in GitHub Desktop.

Select an option

Save spacebit-official/831a7068f46bba1b69e94800581381c7 to your computer and use it in GitHub Desktop.
curl
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //http/https адрес
curl_setopt($ch, CURLOPT_NOBODY, true); //без тела
curl_setopt($ch, CURLOPT_HEADER, true); //смотреть заголовки
curl_setopt($ch, CURLOPT_COOKIE, 'cookie=777'); //отправляем куки
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //следование за перенаправлением
curl_setopt($ch, CURLOPT_FILE, $fp); // запись в файл *третий аргумент это дескриптор файла
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //запись в переменную
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
$res = curl_exec($ch); //выполнение запроса
curl_close($ch); //завершение сеанса
function get_content($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment