Jump to content
Sign in to follow this  
SandySynaptik

Problem In Sending Request And Arranging Returned Request In Webpage

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

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

What is wrong in this script?

 <?php echo $pieces[4], $pieces[5];?>

I am trying to echo 2 variable in same line.

Share this post


Link to post
Share on other sites

There shouldn'e be anything wrong with it. What happens when you try that code?

Share this post


Link to post
Share on other sites

Oh ######! I posted wrong thing. Actually I was trying to put a comma and space between pieces[4] and pieces[5] and the code was something like this

<?php echo $pieces[4],", " $pieces[5];?>

Share this post


Link to post
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

Share this post


Link to post
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>

Share this post


Link to post
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;?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...