-5

Here is my code

    $ip=$_SERVER['REMOTE_ADDR'];

    $url=file_get_contents("http://whatismyipaddress.com/ip/$ip");

    preg_match_all('/<th>(.*?)<\/th><td>(.*?)<\/td>/s',$url,$output,PREG_SET_ORDER);

    $isp=$output[1][2];

    $city=$output[9][2];

    $state=$output[8][2];

    $zipcode=$output[12][2];

    $country=$output[7][2];

    ?>
    <body>
    <table align="center">
    <tr><td>ISP :</td><td><?php echo $isp;?></td></tr>
    <tr><td>City :</td><td><?php echo $city;?></td></tr>
    <tr><td>State :</td><td><?php echo $state;?></td></tr>
    <tr><td>Zipcode :</td><td><?php echo $zipcode;?></td></tr>
    <tr><td>Country :</td><td><?php echo $country;?></td></tr>
    </table>
    </body>

How do I find out the ISP provider of a person viewing a PHP page?

Is it possible to use PHP to track or reveal it?

Error: https://i.stack.imgur.com/3Fop9.png

Curl Scrapping

<?php
$curl_handle=curl_init();
curl_setopt( $curl_handle, CURLOPT_FOLLOWLOCATION, true );
$url='http://www.whatismyipaddress.com/ip/132.123.23.23';
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);

curl_close($curl_handle);
preg_match_all('/<th>(.*?)<\/th><td>(.*?)<\/td>/s',$url,$output,PREG_SET_ORDER);
echo $query;
$isp=$output[1][2];

$city=$output[9][2];

$state=$output[8][2];

$zipcode=$output[12][2];

$country=$output[7][2];
?>
<body>
<table align="center">
<tr><td>ISP :</td><td><?php echo $isp;?></td></tr>
<tr><td>City :</td><td><?php echo $city;?></td></tr>
<tr><td>State :</td><td><?php echo $state;?></td></tr>
<tr><td>Zipcode :</td><td><?php echo $zipcode;?></td></tr>
<tr><td>Country :</td><td><?php echo $country;?></td></tr>
</table>
</body>

Error: https://i.stack.imgur.com/bLdj0.png

What's is wrong with my code here? Any alternative code , that i can use here.

I am not able to scrape that data as described here. https://i.stack.imgur.com/bLdj0.png

P.S. Please post full code. It would be easier for me to understand.

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
Thomas Cox
  • 309
  • 4
  • 12
  • Okay a hint, as I am not a rude person: You're `preg_match`ing the wrong string. Look careful in every line and you will see it – dan-lee May 05 '12 at 11:32

1 Answers1

1

You may not use a script, agent, application or otherwise query this website in an automated fashion without prior written permission.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Yeah, so. Why not downvote other answers also , this? Assuming i have permission? – Thomas Cox May 05 '12 at 10:56
  • Arguing with a person, is against rules of this QA Site. – Thomas Cox May 05 '12 at 10:57
  • 1
    He's not arguing with you, he is just stating the truth. *You are not allowed to do this on this service*. Deal with it. – dan-lee May 05 '12 at 11:00
  • Please download these also, http://stackoverflow.com/a/7268478/1376289 ,http://stackoverflow.com/a/5428909/1376289 , and i see 10 more questions with same answer. Please remove those also. – Thomas Cox May 05 '12 at 11:09