3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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( '&nbsp;',); 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('&nbsp;', '', $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> '; } ?>
Output for 7.0.0 - 7.1.7
Notice: Undefined index: REQUEST_METHOD in /in/uUksV on line 97 Warning: fopen(capcha.jpg): failed to open stream: Permission denied in /in/uUksV on line 70 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/uUksV on line 72 Notice: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' in /in/uUksV on line 73 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/uUksV on line 74 Notice: Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' in /in/uUksV on line 75 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' in /in/uUksV on line 76 Notice: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' in /in/uUksV on line 77 Notice: Use of undefined constant CURLOPT_NOPROGRESS - assumed 'CURLOPT_NOPROGRESS' in /in/uUksV on line 78 Notice: Use of undefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING' in /in/uUksV on line 79 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in /in/uUksV on line 80 Notice: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /in/uUksV on line 81 Notice: Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' in /in/uUksV on line 82 Notice: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' in /in/uUksV on line 83 Notice: Use of undefined constant CURLOPT_COOKIE - assumed 'CURLOPT_COOKIE' in /in/uUksV on line 84 Notice: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' in /in/uUksV on line 85 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/uUksV on line 86 Notice: Use of undefined constant CURLOPT_COOKIEJAR - assumed 'CURLOPT_COOKIEJAR' in /in/uUksV on line 87 Notice: Use of undefined constant CURLOPT_FILE - assumed 'CURLOPT_FILE' in /in/uUksV on line 88 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/uUksV:90 Stack trace: #0 /in/uUksV(243): get_capcha('http://www1.ptt...', 'capcha.jpg') #1 {main} thrown in /in/uUksV on line 90
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Notice: Undefined index: REQUEST_METHOD in /in/uUksV on line 97 Warning: fopen(capcha.jpg): failed to open stream: Permission denied in /in/uUksV on line 70 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/uUksV on line 72 Notice: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' in /in/uUksV on line 73 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/uUksV on line 74 Notice: Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' in /in/uUksV on line 75 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' in /in/uUksV on line 76 Notice: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' in /in/uUksV on line 77 Notice: Use of undefined constant CURLOPT_NOPROGRESS - assumed 'CURLOPT_NOPROGRESS' in /in/uUksV on line 78 Notice: Use of undefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING' in /in/uUksV on line 79 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in /in/uUksV on line 80 Notice: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /in/uUksV on line 81 Notice: Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' in /in/uUksV on line 82 Notice: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' in /in/uUksV on line 83 Notice: Use of undefined constant CURLOPT_COOKIE - assumed 'CURLOPT_COOKIE' in /in/uUksV on line 84 Notice: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' in /in/uUksV on line 85 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/uUksV on line 86 Notice: Use of undefined constant CURLOPT_COOKIEJAR - assumed 'CURLOPT_COOKIEJAR' in /in/uUksV on line 87 Notice: Use of undefined constant CURLOPT_FILE - assumed 'CURLOPT_FILE' in /in/uUksV on line 88 Fatal error: Call to undefined function curl_init() in /in/uUksV on line 90
Process exited with code 255.