3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
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.
Output for 8.0.14 - 8.0.30
Deprecated: Required parameter $file follows optional parameter $url 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.
Output for 8.0.0 - 8.0.13
Deprecated: Required parameter $file follows optional parameter $url in /in/uUksV on line 68 Warning: Undefined array key "REQUEST_METHOD" in /in/uUksV on line 97 Warning: fopen(capcha.jpg): Failed to open stream: Read-only file system 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.
Output for 7.4.33
Notice: Undefined index: REQUEST_METHOD in /in/uUksV on line 97 Warning: fopen(capcha.jpg): failed to open stream: Read-only file system in /in/uUksV on line 70 Warning: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 72 Warning: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 73 Warning: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 74 Warning: Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' (this will throw an Error in a future version of PHP) in /in/uUksV on line 75 Warning: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 76 Warning: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 77 Warning: Use of undefined constant CURLOPT_NOPROGRESS - assumed 'CURLOPT_NOPROGRESS' (this will throw an Error in a future version of PHP) in /in/uUksV on line 78 Warning: Use of undefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING' (this will throw an Error in a future version of PHP) in /in/uUksV on line 79 Warning: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 80 Warning: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 81 Warning: Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 82 Warning: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' (this will throw an Error in a future version of PHP) in /in/uUksV on line 83 Warning: Use of undefined constant CURLOPT_COOKIE - assumed 'CURLOPT_COOKIE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 84 Warning: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 85 Warning: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 86 Warning: Use of undefined constant CURLOPT_COOKIEJAR - assumed 'CURLOPT_COOKIEJAR' (this will throw an Error in a future version of PHP) in /in/uUksV on line 87 Warning: Use of undefined constant CURLOPT_FILE - assumed 'CURLOPT_FILE' (this will throw an Error in a future version of PHP) 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 7.4.26 - 7.4.32
Notice: Undefined index: 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 Warning: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 72 Warning: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 73 Warning: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 74 Warning: Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' (this will throw an Error in a future version of PHP) in /in/uUksV on line 75 Warning: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 76 Warning: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 77 Warning: Use of undefined constant CURLOPT_NOPROGRESS - assumed 'CURLOPT_NOPROGRESS' (this will throw an Error in a future version of PHP) in /in/uUksV on line 78 Warning: Use of undefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING' (this will throw an Error in a future version of PHP) in /in/uUksV on line 79 Warning: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 80 Warning: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 81 Warning: Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 82 Warning: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' (this will throw an Error in a future version of PHP) in /in/uUksV on line 83 Warning: Use of undefined constant CURLOPT_COOKIE - assumed 'CURLOPT_COOKIE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 84 Warning: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 85 Warning: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 86 Warning: Use of undefined constant CURLOPT_COOKIEJAR - assumed 'CURLOPT_COOKIEJAR' (this will throw an Error in a future version of PHP) in /in/uUksV on line 87 Warning: Use of undefined constant CURLOPT_FILE - assumed 'CURLOPT_FILE' (this will throw an Error in a future version of PHP) 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 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.25
Warning: fopen(capcha.jpg): failed to open stream: Read-only file system in /in/uUksV on line 70 Warning: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 72 Warning: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 73 Warning: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 74 Warning: Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' (this will throw an Error in a future version of PHP) in /in/uUksV on line 75 Warning: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 76 Warning: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' (this will throw an Error in a future version of PHP) in /in/uUksV on line 77 Warning: Use of undefined constant CURLOPT_NOPROGRESS - assumed 'CURLOPT_NOPROGRESS' (this will throw an Error in a future version of PHP) in /in/uUksV on line 78 Warning: Use of undefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING' (this will throw an Error in a future version of PHP) in /in/uUksV on line 79 Warning: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 80 Warning: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 81 Warning: Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' (this will throw an Error in a future version of PHP) in /in/uUksV on line 82 Warning: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' (this will throw an Error in a future version of PHP) in /in/uUksV on line 83 Warning: Use of undefined constant CURLOPT_COOKIE - assumed 'CURLOPT_COOKIE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 84 Warning: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' (this will throw an Error in a future version of PHP) in /in/uUksV on line 85 Warning: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' (this will throw an Error in a future version of PHP) in /in/uUksV on line 86 Warning: Use of undefined constant CURLOPT_COOKIEJAR - assumed 'CURLOPT_COOKIEJAR' (this will throw an Error in a future version of PHP) in /in/uUksV on line 87 Warning: Use of undefined constant CURLOPT_FILE - assumed 'CURLOPT_FILE' (this will throw an Error in a future version of PHP) 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 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Warning: fopen(capcha.jpg): failed to open stream: Read-only file system in /in/uUksV on line 70 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.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Warning: fopen(capcha.jpg): failed to open stream: Read-only file system in /in/uUksV on line 70 Fatal error: Call to undefined function curl_init() in /in/uUksV on line 90
Process exited with code 255.

preferences:
300.06 ms | 402 KiB | 381 Q