1

So im basically trying to call an API that is supposed to ping a given IP address, but everything ive been trying hasn't been working, they used to work in the past because these are just snippets i gathered from an old project that used to work just fine, now they dont work, ive checked to see if it logged any PHP errors, but there was nothing in the logs.

Here are my sample codes:

cURL:

<?php


if (Isset($_POST['submit'])){

$host = $_POST['host'];
$url = "http://someapi.com/ping/?host=".$host;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
}

?>

<input type="text" name="host" placeholder="IP" />
<input type="submit" name="submit" value="Geo Locate" />
<br>
<center>
<?php echo $data; ?>
</center>


</form>

@File_Get_Contents

<form action="" method="POST">

<?php



If(Isset($_POST['submit'])){
$host = $_POST['host'];
$api = @File_Get_Contents("http://someapi.com/ping/?host=" .$host. "");
echo $api;
}

?>

<input type="text" name="host" placeholder="IP" />
<input type="submit" name="submit" value="Geo Locate" />
<br>
<center>
<?php echo $api; ?>
</center>
</form>

could it be something wrong with my hosting service maybe?

  • `trying to call an API that is supposed to ping a given IP address`. put `ip address` manually and hit the api directly through browser (by pasting url directly in browser)and see anything coming or not? if yes then there will be problem in code. Also post that `url` and it's output in your question – Alive to die - Anant Aug 16 '16 at 04:51
  • Also `@` used for skipping errors. so remove that. – Alive to die - Anant Aug 16 '16 at 04:52
  • i found my error, failed to open stream: HTTP request failed! – Nightmare Apocalypse Aug 16 '16 at 05:05
  • now you can easily find out the solution for that (i hope so). some example links:- http://stackoverflow.com/questions/697472/why-file-get-contents-returns-failed-to-open-stream-http-request-failed http://stackoverflow.com/questions/4608788/php5-giving-failed-to-open-stream-http-request-failed-error-when-using-fopen http://stackoverflow.com/questions/9574130/file-get-contents-failed-to-open-stream-http-request-failed-http-1-1-404-not – Alive to die - Anant Aug 16 '16 at 05:09

0 Answers0