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?

4
  • 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 Commented Aug 16, 2016 at 4:51
  • Also @ used for skipping errors. so remove that. Commented Aug 16, 2016 at 4:52
  • i found my error, failed to open stream: HTTP request failed! Commented Aug 16, 2016 at 5:05
  • now you can easily find out the solution for that (i hope so). some example links:- stackoverflow.com/questions/697472/… stackoverflow.com/questions/4608788/… stackoverflow.com/questions/9574130/… Commented Aug 16, 2016 at 5:09

0

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.