www.webdeveloper.com
Results 1 to 4 of 4

Thread: Code for finding location information (city) of a user clicking a link to open a page

  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Question Code for finding location information (city) of a user clicking a link to open a page

    hi everyone,
    I m learning php.. I need code to find out the location information (city and country browser etc ) of a user who clicks a link( which opens another page ) and also sends that info to show on another page. kind of like tracking visitors. I have seen many widgets for such visitor tracking and it would really be helpfull if i could get the code for that. i need to add such patch to my website project and i am stuck on it.

    Isha

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    "I need code to find out the location information"

    You mean a WOEID (Where on Earth ID)?

    If you want to track visitors like a boss you should flash their BIOS with a persistent infection. It's much more robust than LSOs, cookies, or otf javascript/malware right? Just use javascript + a trace and take a guess. You'll at least be in the correct country. You can make your own backend nmap analytic script...

    More than anything: respect the privacy of end users, if they want you to know where they are from you can use this alternative method (an html form) I made for you:

    PHP Code:
    <?php
    const REDIRECTION 'google.com/privacy_policy';
    const 
    LOGFILE 'locations.log';
    session_start();
    if (isset(
    $_SESSION['where'])) { header("Location: ".REDIRECTION); exit; }

    $payload = isset($_POST['permission']) && !empty($_POST['permission']) ? $_SERVER['REMOTE_ADDR'] . "/t/t" $_POST['where'] . "/r/n"null;

    if (
    $payload) {
       
    file_put_contents(LOGFILE$payload, (file_existsLOGFILE ) ? FILE_APPEND LOCK_EX));
       
    $_SESSION['location'] = $_POST['where'];
       
    header("Location: ".REDIRECTION);
       exit;
    }

    ?><!DOCTYPE html>
    <html>
    <head>
      <title>Where are you?</title>
    </head>
    <body>

    <div>

    <form target="_self" method="post">
    <span style="clear:both;">Where are you from?</span>
    <input type="text" name="where" />
    <br />
    Check this if you would like us to write this data to a log:
    <input type="checkbox" name="permission" />
    <br />
    <input type="submit" name="s">
    </form>

    </div>
    </body>
    </html>
    That should work, I did not bother to test it. It also records their answers to a logfile, and the very first PHP line lets you put a URL in the string to redirect them to a new page once they answer.


    Edit:
    If you want to see how the pros do it, they send a pixel(1x1) and use long polling to constantly send information back between server and client. They piggyback information like this: google.com/16bit.gif?all_the_info_your_browser_will_give_up=always

    It has something to do with writing a privacy policy, then writing code that uses a loophole in the privacy policy... control structures
    Last edited by eval(BadCode); 04-25-2011 at 02:58 AM.
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

  3. #3
    Join Date
    Mar 2010
    Posts
    128
    If you want to find a users location, there are many different ways to do this. All of which use some type of database to make the relation between the IP and the location. Here is an example, however it is not very well on target:

    $location=file_get_contents('http://api.hostip.info/get_html.php?ip='.$_SERVER['REMOTE_ADDR']);


    You could also try something like this, which seems to work a lot better and is free: http://www.tek-tips.com/viewthread.c...1467015&page=1

  4. #4
    Join Date
    Apr 2006
    Posts
    493
    this will put you pretty close. http://www.ipligence.com/geolocation/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles