0

i want to submit any IP address to this site with cUrl . my cUrl options could not work correctly:

  $h = curl_init();

  curl_setopt($h, CURLOPT_URL, "http://www.whatismyip.com/ip-whois-lookup/"); 
  curl_setopt($h, CURLOPT_POST, true);
  curl_setopt($h, CURLOPT_POSTFIELDS, array(
  'IP' => '2.179.144.117',
  'submitted' => 'submitted'
  ));
  curl_setopt($h, CURLOPT_HEADER, false);
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;

2 Answers 2

1

Give your array data with http_build_query() function so that, it can be decoded correctly on requested IP:

curl_setopt($h, CURLOPT_POSTFIELDS, http_build_query(
   array(
      'IP' => '2.179.144.117',
      'submitted' => 'submitted'
   )
));
// echo http_build_query(array('IP' => '2.179.144.117', 'submitted' => 'submitted'));
// outputs: IP=2.179.144.117&submitted=submitted and this will be added to the end of
// the requested URL in GET request.
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. why i get this error: 403 Forbidden. server of whatismyip.com does not allow access for cUrl?
I don't know how whatismyip.com service usage is, but 403 means the service doesn't allow your IP regardless of using cUrl.
0

A quick check on the headers sent to that webpage, reveals that the "submitted" post variable should be set to true, not to submitted.

Remark: please note that whatismyip.com probably does not allow access to its tool by means of scraping.

1 Comment

As user3280126 also states, you should pass the post data as "IP=2.179.144.117&submitted=true". I must've looked over it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.