WItam, mam problem. Chcę pobrać obrazek kodu captchy z pewnej strony, umiem go pobrać, ale za każdym odświeżeniem jest inny kod a captcha na stronie działa tak że do sesji jest przypisany kod i za jego pomocą jest generowany obrazek z tym samym kodem ale innym wyglądem.
Jeżeli dodam obsługę cookie do kodu, w którym pobieram obrazek to dostaję w outpucie: obrazek xxx nie może zostać wyświetlony...
  1. <?php
  2. define('COOKIE', './cookie.txt');
  3.  
  4.  
  5. $proxies = array( array( 'ip' => '217.96.70.150', 'port' => '8080' ) );
  6. $agent = 'Mozilla/5.0 (X11; U; Linux i686; en-US)';
  7.  
  8.  
  9. $curl = curl_init();
  10.  
  11. curl_setopt( $curl, CURLOPT_URL, 'xxxxxxxxx' );
  12. curl_setopt( $curl, CURLOPT_REFERER, 'http://www.mechanik.civ.pl' );
  13. curl_setopt( $curl, CURLOPT_USERAGENT, $agent );
  14. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
  15. curl_setopt( $curl, CURLOPT_COOKIE, 1 );
  16. curl_setopt( $curl, CURLOPT_COOKIEJAR, COOKIE );
  17. curl_setopt( $curl, CURLOPT_COOKIEFILE, COOKIE );
  18.  
  19. curl_setopt( $curl, CURLOPT_HTTPPROXYTUNNEL, TRUE );
  20.  
  21. curl_setopt( $curl, CURLOPT_PROXY, $proxies[0]['ip'] . ':' . $proxies[0]['port'] );
  22.  
  23. $codepage = curl_exec( $curl );
  24.  
  25. curl_close( $curl );
  26. /////
  27.  
  28.  
  29. $ch = curl_init( 'xxxxxxxxxxxxxxx' );
  30.  
  31. if( !$ch )
  32. {
  33. die( 'Nie mozna zainicjalizowac curla' );
  34. }
  35.  
  36. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  37. curl_setopt($ch, CURLOPT_COOKIESESSION, true); //jesli usune te linijki to nie ma problemu z blednym obrazkiem ale sesja sie nie zachowuje
  38. curl_setopt($ch, CURLOPT_COOKIE, 1 ); //ta linia tez
  39. curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
  40. curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  42. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  43. curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
  44.  
  45. $data = curl_exec($ch);
  46.  
  47. curl_close($ch);
  48.  
  49. header("Content-type: image/png");
  50.  
  51. print($data);
  52.  
  53. ?>