Issue with cURL


Joined
Apr 29, 2021
Messages
4
Reaction score
0
Hello! I'm learning cURL for a project I'm working on with the Pterodactyl API and I don't know why my code isn't working (the entire page won't load). It should respond with "Hello, (my name)!". The cookies are sat to my info, so I don't know what's wrong.
PHP:
<h1>Hello, <?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $_COOKIE["phpdactyl-host"]."/api/client/account",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_COOKIE => 'pterodactyl_session=eyJpdiI6InhIVXp5ZE43WlMxUU1NQ1pyNWRFa1E9PSIsInZhbHVlIjoiQTNpcE9JV3FlcmZ6Ym9vS0dBTmxXMGtST2xyTFJvVEM5NWVWbVFJSnV6S1dwcTVGWHBhZzdjMHpkN0RNdDVkQiIsIm1hYyI6IjAxYTI5NDY1OWMzNDJlZWU2OTc3ZDYxYzIyMzlhZTFiYWY1ZjgwMjAwZjY3MDU4ZDYwMzhjOTRmYjMzNDliN2YifQ%253D%253D',
  CURLOPTS_HTTPHEADER => array(
    Accept: application/json,
    Content-Type: application/json,
    Authorization: $_COOKIE["phpdactyl-key"]
  )
));

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

curl_close($curl);

if ($err) {
  echo "Error:" . $err;
} else {
$obj = json_decode($response);
echo $obj->attributions->first_name;
}?> <?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $_COOKIE["phpdactyl-host"]."/api/client/account",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_COOKIE => 'pterodactyl_session=eyJpdiI6InhIVXp5ZE43WlMxUU1NQ1pyNWRFa1E9PSIsInZhbHVlIjoiQTNpcE9JV3FlcmZ6Ym9vS0dBTmxXMGtST2xyTFJvVEM5NWVWbVFJSnV6S1dwcTVGWHBhZzdjMHpkN0RNdDVkQiIsIm1hYyI6IjAxYTI5NDY1OWMzNDJlZWU2OTc3ZDYxYzIyMzlhZTFiYWY1ZjgwMjAwZjY3MDU4ZDYwMzhjOTRmYjMzNDliN2YifQ%253D%253D',
  CURLOPTS_HTTPHEADER => array(
    Accept: application/json,
    Content-Type: application/json,
    Authorization: $_COOKIE["phpdactyl-key"]
  )
));

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

curl_close($curl);

if ($err) {
  echo "Error:" . $err;
} else {
$obj = json_decode($response);
echo $obj->attributions->last_name;
}?>!</h1>
Capture.PNG
 
Ad

Advertisements

Joined
Jul 3, 2021
Messages
37
Reaction score
1
Introduce log reporting in your code and see if that will spot a mistake.
Also browser's log for HTTP responses.

Report back once done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top