Good afternoon, dear community.
Recently I had to deal with cURL`, I liked it ... I try to figure it out better.
In this regard, the idea to write a script that would use the capabilities of this library.
Idea:
We have a website where passwords will be posted to the nearest freerolls in all popular poker rooms. It is possible through the form to choose a certain type of game and a certain room. I send the necessary parameters in advance in the script and the headers are processing the final page, only with the information of interest.

What did not work:
Using FireBug, it was determined that the data to be sent is JSON.
Question1: Am I doing the right thing to send the data to http://www.pokerist.by/json/freerolls/filter/ ', and in the headlines I specify http://www.pokerist.by/freerolls/raspisanie-frilovlov/, as a referrer ?? Or is it necessary to send data to http://www.pokerist.by/freerolls/raspisanie-frirollov and set the transition on the reader in options?
Question 2: why, after working out the script as a result, I get NULL. Where is the error ?? It turns out that the data was not sent ??
Question3: why run the script, in FireBug, I see only (see screen 3), and I do not see the headers sent by the curl?

FireBug Screenshots

<?php $data = array( "rooms"=>[4],"games"=>["HOLDEM_NOLIMIT"],"daysToDisplay"=>3, "payOutTypes"=>[0,1,2],"maxPayout"=>"100000","minPayout"=>"0","isDeposited"=>false, "isPassworded"=>true,"isByinned"=>false,"isTicketed"=>false,"isOtherConditioned"=>false, "isNoRestriction"=>false,"isPrivate"=>false ); $json_data = json_encode($data); $curl_desc = curl_init('http://www.pokerist.by/json/freerolls/filter/'); curl_setopt($curl_desc, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); curl_setopt($curl_desc, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); curl_setopt($curl_desc, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl_desc, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl_desc, CURLOPT_POSTFIELDS, $json_data); curl_setopt($curl_desc, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_desc, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($json_data), 'Referer: http://www.pokerist.by/freerolls/raspisanie-frirollov/', 'X-Requested-With: XMLHttpRequest', 'Accept: application/json, text/javascript, */*; q=0.01') ); $result = curl_exec($curl_desc); var_dump(json_decode($result)); 

What I see on the original site
Headlines: What I see on the original site:

POST data enter image description here

What I see in FireBug`e after running my script: enter image description here

This is not a parser and not a content grabber, I respect the work of developers and copyrights. No goals other than "figuring out how it works and what I do wrong," I do not pursue. Thank you for your time and your experience.

    1 answer 1

    The server returns HTML code, not JSON. Therefore, json_decode returns NULL.

    enter image description here

    enter image description here

    You can find out if the request was sent or not by including the log:

     $curl_log = fopen("curl_log.txt", 'w+'); curl_setopt($curl_desc, CURLOPT_STDERR, $curl_log); curl_setopt($curl_desc, CURLOPT_VERBOSE, TRUE); 
    • Thank you. Indeed, removing json_decode (), I received the necessary data. For the log - a special thank you. - Andrey Shelest