Jump to content

Couldn't Resolve Host (cURL)


Go to solution Solved by requinix,

Recommended Posts

Hello. I'm fairly new to PHP, and unfortunately the specificity of my problem means I have to just ask about it: I am using Eventbrite's API and cURL, pulling data into a table (formatted through DataTables) and I am getting this "Couldn't resolve host" error, for approximately the first 11 pages, at which point I am presented with the data formatted as expected.

Here is the result: https://tinyurl.com/yde49f3d

Any help is much appreciated, this one has me beat-down and put my junior-level programmer ego in check!

And here is the back-end code: https://pastebin.com/pCSkU6UQ

Note: function u() and function h() are urlencode() and htmlspecialchars(), respectively. Thanks!

Edit: Realized I wouldn't click the link to look at code in another tab, so here's the code directly:

<table id="events" class="display compact" width="100%">

<thead>

<tr>

<th>Event ID</th>

<th>Event Name</th>

<th>Location</th>

<th>Description</th>

<th>Link</th>

<th>Time</th>

<th>Date</th>

<th>Add Event</th>

<th>View Attendees</th>

</tr>

</thead>

<tbody>

 

<?php

 

$token = "IPUTMYAPITOKENINTOAPUBLICPOSTONTHEINTERNET";

$pageNumber = 0;

$continuationToken = "";

 

$curl = curl_init();

 

curl_setopt_array($curl, array(CURLOPT_URL => "https://www.eventbriteapi.com/v3/users/me/owned_events/?token=IPUTMYAPITOKENINTOAPUBLICPOSTONTHEINTERNET",

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => "",

CURLOPT_TIMEOUT => 30,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => "GET"

));

$urlloop = u(h('https://www.eventbriteapi.com/v3/users/me/owned_events/?'));

 

$response = curl_exec($curl);

$err = curl_error($curl);

if ($err) {

echo "cURL Error #:" . $err;

} else {

// Stores the json response data in an array

$array = json_decode($response, true);

}

?>

<?php

 

for($i = 0; $i < $array["pagination"]["page_count"]; $i++) {

if($array["pagination"]["has_more_items"] === true) {

for($j = 0; $j < $array["pagination"]["page_size"]; $j++) {

 

$continuationToken = $array["pagination"]["continuation"];

$newurl = '"';

$newurl .= $urlloop;

$newurl .= "continuation=";

$newurl .= $continuationToken;

$newurl .= "&token=";

$newurl .= $token;

$newurl .= "&page=";

$newurl .= $pageNumber;

$newurl .= '"';

curl_setopt_array($curl, array(CURLOPT_URL => $newurl,

CURLOPT_CUSTOMREQUEST => "GET"));

$response = curl_exec($curl);

 

$err = curl_error($curl);

if ($err) {

echo "cURL Error #:" . $err;

} else {

 

$array = json_decode($response, true);

}

$event_id = $array['events'][$j]['id'];

$event_name = $array['events'][$j]['name']['text'];

$location = $array['events'][$j]['venue_id'];

$description = $array['events'][$j]['description']['text'];

$link = $array['events'][$j]['url'];

$time = $array['events'][$j]['start']['local'];

$date = $array['events'][$j]['start']['local'];

?>

 

<tr><td><?php echo($event_id);?></td>

<td><?php echo ($event_name);?></td>

<td><?php echo ($location);?></td>

<td><?php echo ($description);?></td>

<td><?php echo ($link);?></td>

<td><?php echo ($time);?></td>

<td><?php echo ($date);?></td>

<td><a href=<?php echo 'add-events.php?id=' . $event_id . '&name=' . h(u($event_name)) ?>><button class="btn btn-default btn-md">Add Event</button></a></td>

<td><a href=<?php echo 'show-attendees.php?id=' . $event_id . '&name=' . h(u($event_name)) ?>><button class="btn btn-default btn-md">View Attendees</button></a></td></tr>

 

<?php

}

}

$pageNumber++;

}

?>

</tbody>

</table>

<script>

 

$('#events').dataTable( {

"autoWidth": false,

"columns": [

{ "width": "5%" },

{ "width": "10%" },

{ "width": "5%" },

{ "width": "75%" },

{ "width": "5%" },

]

} );

</script>

 

<?php curl_close($curl); ?>

<?php

include_once('footer.php');

?>

</body>

Edited by requinix
Link to comment
https://forums.phpfreaks.com/topic/305935-couldnt-resolve-host-curl/
Share on other sites

  • Solution

Ah, I forgot to reply after making that edit :P

 

Look at what you're doing with the URLs:

$newurl = '"';
$newurl .= $urlloop;
$newurl .= "continuation=";
$newurl .= $continuationToken;
$newurl .= "&token=";
$newurl .= $token;
$newurl .= "&page=";
$newurl .= $pageNumber;
$newurl .= '"';
There are quotes in it. Quotes. That's definitely not valid.

 

I'm also very concerned about how often you're hitting that URL: dozens of times per page. Surely you can move the cURL call out of those loops?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.