Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

New Extension : IP Based Google Map

edited November 2006 in Vanilla 1.0 Help
I have just uploaded my first add-on for Vanilla. I am a new member to the community and think the Vanilla Forum system is great.
I wanted to write and extension and after looking couldn't find anything like this. IP Based Google Map

This is really a proof of concept idea, it hadn't been done as far as I can tell and as I am usually a Windows .Net developer I wanted to see if I could do it. so the coding may not be the best you have seen.

It basically gets the ip address of the user and does a lat/long lookup and links into Google Maps

Please feel free to let me know how to make the code better and if anyone wants to modify it feel free.

Jon

Comments

  • When I click on a user name I get: Table 'database.LUM_user' doesn't exist
  • I have just installed it onto another machine, running Vanilla and it displays the map correctly on there.
    Perhaps one of the Vanilla/PHP guru's could have a check if the db calls I am making are being made correctly.

    The main ones are

    mysql_connect($Configuration['DATABASE_HOST'],$Configuration['DATABASE_USER'],$Configuration['DATABASE_PASSWORD']);
    mysql_select_db($Configuration['DATABASE_NAME']);
    $result=mysql_query("SELECT RemoteIP FROM ".$Configuration['DATABASE_TABLE_PREFIX']."user WHERE UserID=$AccountUserID") or die(mysql_error());
    Has anyone else who has installed this had a similar problem?

    Jon
  • Well one thing to consider is that there's actually a configuration setting for the user table so you should be using that instead of prefix.user (hope that makes sense it's been a very long day)

    Other than that it looks alright...?
  • edited November 2006
    I don't know why it's not working, but you could try to replace:mysql_connect($Configuration['DATABASE_HOST'],$Configuration['DATABASE_USER'],$Configuration['DATABASE_PASSWORD']); mysql_select_db($Configuration['DATABASE_NAME']); $result=mysql_query("SELECT RemoteIP FROM ".$Configuration['DATABASE_TABLE_PREFIX']."user WHERE UserID=$AccountUserID") or die(mysql_error()); $row = mysql_fetch_row($result); $IPAddress = $row[0];by$IPAddress = $Context->Session->User->RemoteIp;
    Edit: Nevermind, you need the ip of user account that is view...
  • edited November 2006
    if (!@$UserManager) $UserManager = $Context->ObjectFactory->NewContextObject($Context, "UserManager");
    $AccountUserID = ForceIncomingInt("u", $Context->Session->UserID);
    $AccountUser = $UserManager->GetUserById($AccountUserID);

    $IPAddress = $AccountUser->RemoteIp;
  • Thanks for the code snippet Dinoboff, you have no idea how long I spent looking how to get that without a DB call.

    I have added in your code and uploaded a new version 0.2.

    This does not require the db lookup as it uses the code Dinoboff supplied.
  • With the new code, I'm getting "Fatal error: Call to undefined function: stripos() in /home/lookhere/public_html/forum/extensions/IPMap/default.php on line 39" Any ideas?
  • edited November 2006
    stripos() is Available in php 5.0 and higher
  • stripos() is Available in php 5.0 and higher

    this is bad
  • v0.2.1 is uploaded.

    If have now removed the stripos() and used strpos() which I believe is php3/4/5 compatible.
  • cool, no errors at all thanks

    but it does'nt show up any map there in the userprofile .. so i bet this could take a few hours right?
  • It could be the geolocator doesn't know the lat/long of the ip address.
    If you look in the default.php you will see the following lines

    $URL = "http://api.hostip.info/get_html.php?ip=";
    $URL .= $IPAddress;
    $URL .= "&position=true";

    So if you put into you browser http://api.hostip.info/get_html.php?ip=THEIPADDRESS&position=true and see what it returns

    If the latitude and longitude are empty then it can't locate the city.

    I will see if I can find a better geolocation service to use.
  • well ... im not a very good coder ... or in other words let's talk about css or html but this one was a bit out of my box

    so what should i do? please explain it for scripting idiots like me :D
  • Do you use it localy, on a testing server?
  • i? no, its on a regular webserver
  • edited November 2006
    i figured it out .. it works in opera but not in safari or ff , i guess this extension needs some work

    edit: ah it's seems like its not the browser its the status .. i see the map only in profiles of banned users
  • http://api.hostip.info/get_html.php?ip=60.230.139.189&position=true
    Returns...
    ----------------------------------------------------------------------
    Country: AUSTRALIA (AU)
    City: (Unknown city)
    Latitude:
    Longitude:
    ----------------------------------------------------------------------
    The city is Melbourne, hardly an un-know back water?
This discussion has been closed.