Skip to content

Instantly share code, notes, and snippets.

@thanhlmm
Created November 2, 2016 02:16
Show Gist options
  • Save thanhlmm/f4aba016d5605671bca3e55fcf5fa851 to your computer and use it in GitHub Desktop.
Save thanhlmm/f4aba016d5605671bca3e55fcf5fa851 to your computer and use it in GitHub Desktop.
From CuThanh.com with </3
<?php
function _curl($url, $post = "", $cookie, $ref)
{
$ch = curl_init();
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tao file này nhé, mình không biết là nó có tự tạo cho bạn luôn không
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function getStr($string, $start, $end)
{
$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}
$page1 = _curl ('http://www.vietteltelecom.vn/index.php/captcha', '', '', 'http://www.vietteltelecom.vn');
$customCookie = getStr($page1, 'cookie="', '"+"');
$page2 = _curl ('http://www.vietteltelecom.vn/index.php/captcha', '', $customCookie, 'http://www.vietteltelecom.vn/index.php/captcha');
header("Content-Type: image/png");
echo $page2;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment