function login(&$ch, $username, $password) { curl_setopt($ch, CURLOPT_URL, "http://www.1top.vn/TPHoChiMinh"); initCommonCURL($ch); $output = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "http://www.1top.vn/ajax/login_reg/cdt_login_form?_=" . get_now_for_one_top()); curl_setopt($ch, CURLOPT_REFERER, 'http://www.1top.vn/TPHoChiMinh'); initCommonCURL($ch); $output = curl_exec($ch); $doc = new DOMDocument(); $cdt_csrf_token = null; if (@$doc->loadHTML($output)) { $xpath = new DOMXpath($doc); $elements = $xpath->query("//input[@name='cdt_csrf_token']/@value"); if (!is_null($elements)) { foreach ($elements as $element) { $cdt_csrf_token = $element->nodeValue; } } } curl_setopt($ch, CURLOPT_URL, "http://www.1top.vn/ajax/login_reg/action_login_cdt"); initCommonCURL($ch); curl_setopt($ch, CURLOPT_REFERER, 'http://www.1top.vn/TPHoChiMinh'); $params = array("cdt_csrf_token" => $cdt_csrf_token, "form_name" => "login_cdt", "user_name" => $username, "password" => $password); curl_setopt($ch, CURLOPT_POST, TRUE); $fields_string = ""; foreach ($params as $key => $value) { $fields_string .= $key . '=' . urlencode($value) . '&'; } $fields_string = rtrim($fields_string, '&'); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); $output = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "http://www.1top.vn/TPHoChiMinh"); initCommonCURL($ch); curl_exec($ch); return $output == "{\"code\":1}"; }
function loadDulich(&$loantinIdList) { //http://muachung.vn/san-pham-du-lich.html; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://muachung.vn/san-pham-du-lich.html"); initCommonCURL($ch); $output = curl_exec($ch); $doc = new DOMDocument(); if (@$doc->loadHTML($output)) { $xpath = new DOMXpath($doc); $elements = $xpath->query("//div[@class='titleFirst' or @class='tit']/a/@href"); if (!is_null($elements)) { foreach ($elements as $element) { $url = $element->nodeValue; $matches = array(); preg_match('/\\/p-\\d+\\//', $url, $matches, PREG_OFFSET_CAPTURE); if (count($matches) > 0) { $id = $matches[0][0]; $id = substr($id, 3); $id = substr($id, 0, strlen($id) - 1); if (!in_array($id, $loantinIdList)) { $loantinIdList[] = $id; } } } } } curl_close($ch); }