Jump to content

Problem In Sending Request And Arranging Returned Request In Webpage


SandySynaptik
 Share

Recommended Posts

I am using a web service called Geo I/O which lets me locate an IP address and get their Country, State, City and Latitudinal and Longitudinal status.The request that is sent is something like:http://api.geoio.com/q.php?key=YOUR TOKEN&qt=&d=comma&q=IP ADDRESS The above request sent gives a string like:Calcutta,West Bengal,India,Bcl East,22.5697,88.3697,IN Now I want the above string arranged something like this in the webpage:City: CalcuttaState: West BengalCountry: IndiaLatitude: 22.5697Longitude: 88.3697 Please help me out.

Edited by Sandy Synaptik
  • Like 1
Link to comment
Share on other sites

The problem is how do i sent this request for each of them who visits this page?Below is something I am up to:

<!DOCTYPE html><html lang="en-us"><head><meta charset="utf-8"></head><body><?php$ip = $_SERVER["REMOTE_ADDR"];?></body></html>

Link to comment
Share on other sites

You're missing a comma between the string and the last variable:<?php echo $pieces[4], ", ", $pieces[5];?> Aside from that, the code should work fine. And what is displaying on the page when you use the code?

  • Like 1
Link to comment
Share on other sites

How can I cut down/shorten the following code? looks like I have used too many PHP tags.

<!DOCTYPE html><html lang="en-us"><head>    <meta charset="utf-8"></head><body><?php$IP = $_SERVER["REMOTE_ADDR"];$geodata = file_get_contents('http://api.geoio.com/q.php?key=6wVGBk7TshKizPJI&qt=geoip&d=comma&q=$IP');$pieces = explode(",", $geodata);echo $geodata;?><br />Your city : <?php echo $pieces[0];?><br />Your State: <?php echo $pieces[1];?><br />Your Country: <?php echo $pieces[2];?><br />Your Location (Lat): <?php echo $pieces[4];?><br />Your Location (Long): <?php echo $pieces[5];?><br />Your Location: <a href="http://maps.google.com/?q=<?php echo $pieces[4],", ", $pieces[5];?>"><?php echo $pieces[4],", ", $pieces[5];?></a><br />Your Country Code: <?php echo $pieces[6];?><br /><br />* I can't guaranty geolocational data, don't rely on them.</body></html>

Link to comment
Share on other sites

It's just fine like that. There aren't too many PHP tags as long as there's something besides whitespace between the closing tag ?> and following opening tag <?php You could also put all the HTML into a string, if you wanted to. And use the heredoc syntax.

<?php$IP = $_SERVER["REMOTE_ADDR"];$geodata = file_get_contents('http://api.geoio.com/q.php?key=6wVGBk7TshKizPJI&qt=geoip&d=comma&q=$IP');$pieces = explode(",", $geodata);echo $geodata;echo <<<HTMLCODE<br />Your city : $pieces[0]<br />Your State: {$pieces[1]}<br />Your Country: {$pieces[2]}<br />Your Location (Lat): {$pieces[4]}<br />Your Location (Long): {$pieces[5]}<br />Your Location: <a href="http://maps.google.com/?q={$pieces[4]}, {$pieces[5]}">{$pieces[4]}, {$pieces[5]}</a><br />Your Country Code: {$pieces[6]}<br /><br />HTMLCODE;?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...