2

I have a big problem. I can't manage to find a solution. Data is submitted through a form via GET. The results are then reloaded via AJAX. I have tried every way possible via cURL. The server even throws SQL error messages. But unfortunately, I can't get it to work. Can anyone help me?

#{
#  "searchdata": {
#    "required": "1",
#    "statistics": "1",
#    "offer_name": null,
#    "zip": "01069",
#    "location": null,
#    "maxdistance": "5",
#    "target_group": null,
#    "age_group": null,
#    "language": null,
#    "sort": "zip_asc",
#    "record_offset": 0
#  }
#}

#Test-URL = https://pflegefinder.bkk-dachverband.de/aua/searchresult.php?searchdata%5Brequired%5D=1&searchdata%5Bstatistics%5D=1&searchdata%5Boffer_name%5D=&searchdata%5Bzip%5D=01069&searchdata%5Blocation%5D=&searchdata%5Bmaxdistance%5D=5&searchdata%5Btarget_group%5D=&searchdata%5Bage_group%5D=&searchdata%5Blanguage%5D=&searchdata%5Bsort%5D=zip_asc&searchdata%5Brecord_offset%5D=0

 $data = array("required" => "1","statistics"=>"1","offer_name" => null,"zip" => "51143","location" => null,"maxdistance" => "20","target_group" =>  null,"age_group" =>  null,"language" => null, "sort" => "zip_asc", "record_offset" => 0);
 $data_string = urlencode(json_encode($data));

    $url = "https://pflegefinder.bkk-dachverband.de/aua/rest_searchresult.php?".date("U");
    $ch = curl_init();
    // set post fields
    curl_setopt($ch, CURLOPT_URL, ($url));
#   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie: MK_CookieConsent={"required":true,"statistics":true},PHPSESSID="6ldq1ffekjeum41gr3b4bp5tqm"'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    #curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    #curl_setopt($ch, CURLOPT_POSTFIELDS,'searchdata[required]=1&searchdata[statistics]=1&searchdata[offer_name]=&searchdata[zip]=01069&searchdata[location]=&searchdata[maxdistance]=5&searchdata[target_group]=&searchdata[age_group]=&searchdata[language]=&searchdata[sort]=distance_asc&searchdata[record_offset]=0');
    curl_setopt($ch, CURLOPT_POSTFIELDS,array("searchdata"=>$data_string));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
    curl_setopt($ch, CURLOPT_REFERER, 'https://pflegefinder.bkk-dachverband.de/aua/searchresult.php?searchdata%5Brequired%5D=1&searchdata%5Bstatistics%5D=1&searchdata%5Boffer_name%5D=&searchdata%5Bzip%5D=51143&searchdata%5Blocation%5D=&searchdata%5Bmaxdistance%5D=5&searchdata%5Btarget_group%5D=&searchdata%5Bage_group%5D=&searchdata%5Blanguage%5D=&searchdata%5Bsort%5D=distance_asc&searchdata%5Brecord_offset%5D=0');
#   curl_setopt($ch, CURLOPT_REFERER, 'https://pflegefinder.bkk-dachverband.de/aua/');
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_VERBOSE, '0');
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile2.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile2.txt");
    curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
    $seite = curl_exec($ch); 
    curl_close($ch);
1
  • You've spelt language as laguage and that's causing the SQL errors. Commented Feb 13, 2022 at 21:44

1 Answer 1

1

The misspelling of laguage (supposed to be language is causing the SQL errors that you are seeing.

I don't write much PHP anymore, I used the Insomnia HTTP client to enter your request which is how I spotted the mistake. I exported the code below which works great for me.

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://pflegefinder.bkk-dachverband.de/aua/rest_searchresult.php",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n\t\"searchdata\": {\n\t\t\"required\": 1,\n\t\t\"offer_name\": null,\n\t\t\"zip\": 51143,\n\t\t\"location\": null,\n\t\t\"maxdistance\": 20,\n\t\t\"target_group\": null,\n\t\t\"age_group\": null,\n\t\t\"language\": null,\n\t\t\"sort\": \"zip_asc\",\n\t\t\"record_offset\": 0\n\t}\n}",
  CURLOPT_COOKIE => "PHPSESSID=2a4tctjc0ec6potr1p5a0tonir",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yesss, it workz! You are the best!!
That's great! If you could mark this as the correct answer that would help people with similar issues. Many thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.