@ 2014-10-27T17:26:40Z <?php
/* reset */
$tracking_code = $capcha1 = $capcha2 = $data = '';
/* Site 1 */
/* Sometimes this site gives an error so check before you run your request via normal website,
the error comes up at $x("//span[@id='span1']/text()") via firebug console as the russian
"База данных временно недоступна, повторите запрос позже." (database not accessible try again later)
*/
$tracking_code = 'CP021325078TR';
$url1 = 'http://www.russianpost.ru/tracking20/';
$capcha_url1 = 'http://www.russianpost.ru/tracking20/Code/Code.png.ashx';
//$postfields1 = '?BarCode='.$tracking_code.'&Code='.$capcha1; // check I haven't checked this in detail
/* Site 2 */
$url2 = 'http://www1.ptt.gov.tr/tr/interaktif/kayitliposta-yd_yeniweb.php';
$capcha_url2 = 'http://www1.ptt.gov.tr/tr/interaktif/CaptchaSecurityImages.php?width=100&height=40&characters=5';
//$postfields2 = '?barkod='.$tracking_code.'&security_code'.$capcha2; // check I haven't checked this in detail.
function fix_keys($array = null) {
foreach ($array as $k => $val) {
if(is_array($val)) {
$array[$k] = fix_keys($val);
}
}
return array_values($array);
}
function translit_Turkish($inputText) {
$search = array('ç', 'Ç', 'ğ', 'Ğ', 'ı', 'i','I', 'İ', 'ö', 'Ö', 'ş', 'Ş', 'ü', 'Ü', 'Ãœ', 'Ä°', 'ö');
$replace = array('c', 'C', 'g', 'G', 'i', 'i','I', 'I', 'o', 'O', 's', 'S', 'u', 'U', 'U', 'I', 'o');
return str_replace($search, $replace, $inputText);
}
function clean_gunk($input) {
$search = array( ' ',);
return str_replace($search, '', $input);
}
function to_array($DomList) {
$array = array();
foreach($DomList as $list) {
$array[] = $list->nodeValue;
}
return $array;
}
function preview($results = null) {
echo '<pre>';
print_r($results);
echo '<br/>Node Values <br/>';
foreach($results as $result){
echo trim($result->nodeValue).'<br/>';
$array[] = $result;
}
echo '<br/><br/>';
if (isset($array)) {
@print_r($array); // php error : not implemented yet.
}
}
function get_capcha($url = null, $file) {
$cookie = dirname(__FILE__).'/receita.txt.';
$fn = fopen($file,"w+");
$options = array (
CURLOPT_RETURNTRANSFER => TRUE, // dont need webpage data
CURLOPT_BINARYTRANSFER => TRUE, // yes binary.
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_NOPROGRESS => TRUE,
CURLOPT_ENCODING => 'gzip',
CURLOPT_CONNECTTIMEOUT => 240,
CURLOPT_TIMEOUT => 240,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6', // Setting the useragent
CURLOPT_URL => $url, // URL that produces an image captcha.
CURLOPT_COOKIE => 1,
CURLOPT_COOKIESESSION => TRUE,
CURLOPT_COOKIEFILE => $cookie, // do this more under the spell of the captcha
CURLOPT_COOKIEJAR => $cookie, // this over the top make magic .. ah already said that;
CURLOPT_FILE => $fn,
);
$ch = curl_init();
curl_setopt_array($ch,$options);
curl_exec($ch);
curl_close($ch);
fclose($fn);
}
if($_SERVER['REQUEST_METHOD'] == "POST") {
//$capcha1 = trim($_POST['capchacode1']);
//$capcha2 = $_POST['capchacode2'];
$cnpj = $_POST ['cnpj'];
$cnpj2 = $_POST ['cnpj2'];
/*
cURL rel stuff start
*/
$tracking_code = 'CP021325078TR';
$url = "http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php";
$post_fields = 'barkod='.$tracking_code.'&security_code='.$cnpj;
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
$reffer = "http://www1.ptt.gov.tr/tr/interaktif/kayitliposta-yd_yeniweb.php";
$cookie = dirname(__FILE__).'/receita.txt.';
$header = array('Referer: xxx',
'Origin: '.$url,
'Content-Type: application/x-www-form-urlencoded',
'Connection: keep-alive',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Cache-Control: max-age=0',
'Except:');
$options = array (
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_USERAGENT => $agent,
CURLOPT_REFERER => $reffer,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 0,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response2 = curl_exec($ch);
curl_close($ch);
//$response1 <- should be from url1
//$response2 <- should be from url2
/*$url2 = "http://www.russianpost.ru/tracking20/CheckSubscription.js.aspx";
$post_fields2 = 'Id='.$tracking_code.'&Code='.$cnpj2.'&Language=Russian';
$reffer2 = "http://www.russianpost.ru/tracking20/";
// http://www.russianpost.ru/tracking20/CheckSubscription.js.aspx?Id=CP021325078TR&Code=84084&Language=Russian
//http://www.russianpost.ru/tracking20/PostalOrderEventsForMail.js.aspx?Id=CP021325078TR&Code=84084&Language=Russian
$options2 = array (
CURLOPT_URL => $url2,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post_fields2,
CURLOPT_USERAGENT => $agent,
CURLOPT_REFERER => $reffer2,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 0,
);
$ch2 = curl_init();
curl_setopt_array($ch2, $options2);
$response1 = curl_exec($ch2);
curl_close($ch2);
/*S
cURL rel stuff end
*/
print_r($response2);
// for site 1
// query to get text data from page : http://www.russianpost.ru/tracking20/
// "//table[@id='tbl1']//tbody//tr//td/text()"
/*$dom = new DOMDocument();
@$dom->loadHTML($response1);
$xpath = new DOMXPATH($dom);
$data1 = to_array($xpath->query("//table[@id='tbl1']//tbody//tr//td/text()")); // checked query via browser ok
*/
// for site 2
// query to get text data from page : http://www1.ptt.gov.tr/tr/interaktif/sonuc-yd.php
// "(//table)[3]//tbody//tr//td/text()|(//table)[9]//tbody//tr//td/text()"
//$remove = '<html xmlns="http://www.w3.org/1999/xhtml">';
//$response2 = str_replace($remove, '', $response2);
$wr = fopen('temp.txt','w+');
fwrite($wr, $response2);
fclose($wr);
//$response2 = str_replace(' ', '', $response2);
$response2 = iconv('iso-8859-9','utf-8', $response2);
$response2 = clean_gunk(translit_Turkish($response2));
$dom = new DOMDocument();
@$dom->loadHTML($response2);
$xpath = new DOMXPATH($dom);
//preview($xpath2);
//top part
$data = to_array($xpath->query("(//table[3]//tr//text())")); //checked via browser ok.
$data = fix_keys(array_filter($data, create_function('$a','return trim($a)!=="";')));
for($i=0; $i<count($data); $i=$i+5){
$row[] = trim(str_replace(' ','',$data[$i])).','.trim($data[$i+1]).','.trim($data[$i+2]).','.trim($data[$i+3]).','.trim($data[$i+4]);
}
var_dump($row);
//bottom part
$data2 = to_array($xpath->query("(//table[9]//tr//text())")); //checked via browser ok.
$data2 = fix_keys(array_filter($data2, create_function('$a','return trim($a)!=="";')));
unset($data2[0]);
unset($data2[1]);
unset($data2[2]);
$data2 = fix_keys($data2);
for($i=0; $i<count($data2); $i=$i+3){
$row2[] = trim(str_replace(' ','',$data2[$i])).','.trim($data2[$i+1]).','.trim($data2[$i+2]);
}
var_dump($row2);
//preview($data);
// display $data1 and $data2 shouldn't be null if the curl returned the correct result pages.
echo '<pre>';
//var_dump($data1);
//var_dump($data1);
//var_dump($data);
} else {
get_capcha ($capcha_url2, "capcha.jpg");
//get_capcha ($capcha_url1, "capcha2.jpg");
// And create the form that + image shows the input field CNPJ
echo "<img src = 'capcha.jpg' />".
"<img src = 'capcha2.jpg' />".
'<form action = "'.htmlentities($_SERVER['PHP_SELF']).'" method = "POST">
captcha
<input name = "cnpj">
<input name = "cnpj2">
<input type = "submit">
</ form> ';
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Deprecated: Optional parameter $url declared before required parameter $file is implicitly treated as a required parameter in /in/uUksV on line 68
Warning: Undefined array key "REQUEST_METHOD" in /in/uUksV on line 97
Warning: fopen(): open_basedir restriction in effect. File(capcha.jpg) is not within the allowed path(s): (/tmp:/in:/etc) in /in/uUksV on line 70
Warning: fopen(capcha.jpg): Failed to open stream: Operation not permitted in /in/uUksV on line 70
Fatal error: Uncaught Error: Undefined constant "CURLOPT_RETURNTRANSFER" in /in/uUksV:72
Stack trace:
#0 /in/uUksV(243): get_capcha('http://www1.ptt...', 'capcha.jpg')
#1 {main}
thrown in /in/uUksV on line 72
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
53.59 ms | 402 KiB | 8 Q