Guys, save, 3 days I deal with this captcha, cookies, sessions, and in response there is always one thing - wrong captcha.

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> Парсер ;) </title> </head> <body> <?php $url = 'https://my.maerskline.com/tracking/search'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_REFERER, $url); $content = curl_exec($ch); preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $content, $matches); $cookies = array(); foreach($matches[1] as $item) { parse_str($item, $cookie); $cookies = array_merge($cookies, $cookie); } foreach($cookies as $key => $value) { @$cookiee .= $key.'='.$value.';'; } $cookiee = substr($cookiee,-1); $content = str_replace('<img class="pull-left captcha-img" src="', '<img class="pull-left captcha-img" src="https://my.maerskline.com', $content); $content = str_replace('<form action="', '<form action="https://my.maerskline.com', $content); preg_match('/captcha\?id=[0-9A-Za-z\-]{1,100}/',$content,$matches); $id = substr($matches[0],11); preg_match('/captcha\?id=[0-9A-Za-z\-]{1,100}/',$content,$matches); preg_match('/https:\/\/my.maerskline.com\/captchaapp\/captcha\?id=[0-9A-Za-z\-]{1,100}/',$content,$matches); ?> <form action="" method="get"> <input type="hidden" name="randomID" value="<?php echo $id ?>" /> <input type="text" name="searchNumber" placeholder="Номер"/> <img src="<?php echo $matches[0]; ?>"/> <input type="text" name="code" placeholder="Капча"/> <input type="submit" name="send" value="Получить информацию"> </form> <?php if(isset($_GET['send'])) { $url = 'https://my.maerskline.com/tracking/search?randomID='.$id.'&searchNumber='.$_GET['searchNumber'].'&code='.$_GET['code']; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_COOKIE, $cookiee); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); $content = curl_exec($ch); curl_close($ch); echo $content; } ?> </body> </html> 

The most interesting thing is if you take the GET line that generated the locale and insert it here https://my.maerskline.com/tracking/search then it will work! and if you do the same thing with a curl, then a wrong captcha ... I understand that there are problems in the headers, cookies, sessions. But I do not understand how to properly parse and send them, so that it would be exactly the same. Or maybe another problem? Push the thought, please.

  • one
    I think: you parse the page with a curl with your own session and output the captcha address directly to the browser, where there is another session and another captcha code. - check1st
  • I tried to save the picture with the Kurl, the result is still 1 ... - Metalpriest
  • therefore, cookies are not transmitted when uploading a picture and / or submitting a form in the current version it is generally difficult to indicate an error. Try to optimize the code and separate the logic from the output. so it will be easier for you to understand the problem and there will be more people willing to help you. - check1st
  • Thanks for the advice, I will try - Metalpriest

0