Curl only works in terminal not in php -


just simple script curl website take data hobby project. in terminal works php doesnt work @ all. think has cookies

$ch = curl_init();

curl_setopt($ch, curlopt_url, "http://www.pokemongomap.info/includes/mapdata.php");   curl_setopt($ch,curlopt_post, true); curl_setopt($ch,curlopt_returntransfer, true); curl_setopt($ch,curlopt_postfields, 'fromlat=52.352772543694165&tolat=52.353516320168715&fromlng=6.672205448722025&tolng=6.6761080628386935&fpoke=1&fgym=1');       curl_setopt($ch,curlopt_httpheader, array(                      'pragma: no-cache',                 'origin: http://www.pokemongomap.info',                  'accept-encoding: gzip, deflate',                 'accept-language: nl-nl,nl;q=0.8,en-us;q=0.6,en;q=0.4',                  'user-agent: mozilla/5.0 (macintosh; intel mac os x 10_11_4) applewebkit/537.36 (khtml, gecko) chrome/52.0.2743.116 safari/537.36',                  'content-type: application/x-www-form-urlencoded; charset=utf-8',                  'accept: application/json, text/javascript, */*; q=0.01',                  'cache-control: no-cache',                  'cookie: phpsessid=5q2naanh8gj85utl2m96erjfa3; __atssc=reddit%3b1; cookieconsent_dismissed=yes; __atuvc=4%7c33%2c1%7c34; _ga=ga1.2.1355385211.1471162927; latlngzoom=19[##split##]52.35314443349598[##split##]6.674156755780354',                  'x-requested-with: xmlhttprequest',                  'connection: keep-alive',                  'referer: http://www.pokemongomap.info/'         ));   curl_setopt($ch, curlopt_verbose, true);    $output = curl_exec($ch); if ($output === false) {     printf("curl error (#%d): %s<br>\n", curl_errno($ch),            htmlspecialchars(curl_error($ch))); }  curl_close($ch);     var_dump($output); 

returns string(145) "�]��� d���)j�Ûi�Ѡ+4����߅z����d紨)=qw�+g��am~��f;c�6v��^�ng�u jf�ǜ ����{��t�.9�s����=m 9g���gfu��%�[�/��r3|l#�7��h�)�"

when using json_decode returns null.

according php manual curl_setopt, second parameter should int or constant option. try code below:

    $ch = curl_init();      curl_setopt($ch, curlopt_url, "http://www.pokemongomap.info/includes/mapdata.php");      curl_setopt($ch,curlopt_post, true);     curl_setopt($ch,curlopt_returntransfer, true);     curl_setopt($ch,curlopt_postfields, 'fromlat=52.352772543694165&tolat=52.353516320168715&fromlng=6.672205448722025&tolng=6.6761080628386935&fpoke=1&fgym=1');     curl_setopt($ch,curlopt_httpheader, array(               'pragma: no-cache',               'origin: http://www.pokemongomap.info',               'accept-encoding: gzip, deflate',               'accept-language: nl-nl,nl;q=0.8,en-us;q=0.6,en;q=0.4',               'user-agent: mozilla/5.0 (macintosh; intel mac os x 10_11_4) applewebkit/537.36 (khtml, gecko) chrome/52.0.2743.116 safari/537.36',               'content-type: application/x-www-form-urlencoded; charset=utf-8',               'accept: application/json, text/javascript, */*; q=0.01',               'cache-control: no-cache',               'cookie: phpsessid=5q2naanh8gj85utl2m96erjfa3; __atssc=reddit%3b1; cookieconsent_dismissed=yes; __atuvc=4%7c33%2c1%7c34; _ga=ga1.2.1355385211.1471162927; latlngzoom=19[##split##]52.35314443349598[##split##]6.674156755780354',               'x-requested-with: xmlhttprequest',               'connection: keep-alive',               'referer: http://www.pokemongomap.info/'       ));     curl_setopt($ch,curlopt_encoding , "");      curl_setopt($ch, curlopt_verbose, true);       $output = curl_exec($ch);      if ($output === false) {         printf("curl error (#%d): %s<br>\n", curl_errno($ch),                htmlspecialchars(curl_error($ch)));     }      $info = curl_getinfo($ch);      var_dump ($info);     curl_close($ch);     var_dump(json_decode($output)); 

i changed final execution curl errors , curl_info, since using verbose mode, define wrong request.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -