IP to Location Map

August 28, 2009

Sometimes we need to show to visitors of our sites where are they from. In one of my sites, I am using an widget or gadget or something like that to show the location of visitor in map by his/her IP address. I know there are several APIs and several sites offering this service for free or for some credit. For application specific reason I have used 'IPinfodb' api and jmap plugin for jquery. The details are listed as below.

Prerequisites :
1.) CURL or 'allow_url_fopen' be enabled in apache and php.ini
2.) Google or Yahoo map api key. [Here I have used google map]
3.) Download jquery.js file from here here.
4.) Download jmap polugin for jquery from here .

Steps :
(1.) Taking the visitor's IP address by 



<?php
    $remote_ip = $_SERVER['REMOTE_ADDR'];
?>
(2.) Now put the following code to call the API. It returns a formatted xml output.


$request_url = "http://ipinfodb.com/ip_query.php?ip=".$remote_ip;
$xml = simplexml_load_file($request_url) or die("url not loading");


(3.) If we print the variable  $xml , we can find the returned xml structure. It is something like following -

SimpleXMLElement Object
(
    [Ip] => [...The returned IP...]
    [Status] => OK
    [CountryCode] => BD
    [CountryName] => Bangladesh
    [RegionCode] => [... The Map Region Code ...]
    [RegionName] => Dhaka
    [City] => Dhaka
    [ZipPostalCode] => SimpleXMLElement Object
        (
        )

    [Latitude] => 23.7231
    [Longitude] => 90.4086
    [Gmtoffset] => 6.0
    [Dstoffset] => 6.0
)

(4.) As from no#3 we find that this xml object is single dimensional. So we can access its attributes by simple object call. Thus the latitude and longitude can be derived by the following lines -

$lat = $xml->Latitude;
    $lng = $xml->Longitude;

(5.) Now we will geocode the co-ordinates using 'jmap' plugin of jQuery and google map API. The following code do that all.

echo "
<script src=\"http://maps.google.com/maps?file=api&v=2&key=
[... ... Your google map API key ... ...]\" type=\"text/javascript\"></script>
    <script src=\"js/jquery.js\" type=\"text/javascript\"></script>
    <script src=\"js/jquery.jmap.min.js\" type=\"text/javascript\"></script>

    <div id=\"map\" style=\"width: 640px; height: 480px\" align=\"center\"></div>
        <script type=\"text/javascript\">
            (function($){
                $('#map').jmap('init', {mapCenter:[".$lat.",".$lng."]}, function(el,
options){
                    $(el).jmap('addMarker', {pointLatLng:[".$lat.",".$lng."], pointHTML:
\"<div style='height:25px;width:200px;font-weight:bold;padding:5px;text-align:center;'>".
'[... ... The Text You want to display when people click on the marker ... ...]'."<br></div>\"});
                });
            })(jQuery);
        </script>
";

(6.) So the final code for the page / gadget /widget is as follows:

<?php
    $remote_ip = $_SERVER['REMOTE_ADDR'];
    $request_url = "http://ipinfodb.com/ip_query.php?ip=".$remote_ip;
    $xml = simplexml_load_file($request_url) or die("url not loading");
    $lat = $xml->Latitude;
    $lng = $xml->Longitude;

    echo "
<script src=\"http://maps.google.com/maps?file=api&v=2&key=
[... ... Your google map API key ... ...]\" type=\"text/javascript\"></script>
    <script src=\"js/jquery.js\" type=\"text/javascript\"></script>
    <script src=\"js/jquery.jmap.min.js\" type=\"text/javascript\"></script>

    <div id=\"map\" style=\"width: 640px; height: 480px\" align=\"center\"></div>
        <script type=\"text/javascript\">
            (function($){
                $('#map').jmap('init', {mapCenter:[".$lat.",".$lng."]}, function(el, 
options){
                    $(el).jmap('addMarker', {pointLatLng:[".$lat.",".$lng."], pointHTML:
\"<div style='height:25px;width:200px;font-weight:bold;padding:5px;text-align:center;'>".'
[... ... The Text You want to display when people click on the marker ... ...]'."<br></div>\"});
                });
            })(jQuery);
        </script>
";
?>

(7.) Now save the file and host it to server. Whenever you open the page you can find the map and your location is marked in the map.

Opinions and easier ways if there are cordially welcome.
Continue Reading...

First experience to wimax :-)

August 4, 2009

The word that is bubling around in the media and a large number of known people for quite a long time is 'WIMAX'. I've heard of it but never had a chance to use it as it is not open for all till now and the test transmission at my office area (panthopoth) requires a laptop with wi-fi connection which i don't have. This evening i got a chance to use it accidentally. I'm sharing the story now. As I am posting from my 'vanga' nokia 3110c, there may be some problem with text format. I will fix them soon.



I had to sit for some urgent personal project delivery this evening with my buddy 'zanin'. He bought a nice compaq lappy recently. We sat at a staircase near s@ifur's at panthopoth. No longer we started working, a baloon popup just came saying that we had an active network connection. curiously i clicked the wi-fi button and found 2 active connection. i recognize one of them to be an WI-MAX provider (IT CONNECT) as one of my frnd (http://kousikroy.blogspot.cod) work there. immedietly i called him asking what to do. he told me that they are one test untill 8th of august and only sign up will connect me. as soon as i click connect there site opened with browser asking me to sign up or log in. i signed up. they have an 'on the fly' service i.e. no unlimited line and you have to select speed everytime you log in. they charge 0.01tk per kb. (it's pain and i swear i won't use them paying). however, i choose 512kbps i.e. 64kBps and i was on. the speed was without congestion and no disconnection (i used for almost one hour). frankly speaking i am satisfied with the performance but not with the offer of course.


surely i will use wi-max frequently in near future. but the first time deserves special treat. that's why i shared it here.
Continue Reading...

A Nice Article About Principles of Beautiful Web Designs

July 9, 2009

Recently I was searching for a new look to my project and to some good tips regarding web design. I found a beautiful article about principles of good web designs. I thought it is worth sharing. Even if nobody reads it in my blog, it can be useful for future reference for my self.

The original link goes here -
http://www.sitepoint.com/print/principles-beautiful-web-design

The article is by Jason Beaird. Jason Beaird has written 2 articles for SitePoint with an average reader rating of 9. He is a good designer and has dual-majored in graphic design and digital media at the University of Central Florida.

The Article covers areas like

>> The design process
>> Definition of good design
>> Web page anatomy
>> Grid Theory
>> Balance
>> Unity
>> Emphasis
>> Bread-and-butter Layouts
>> Getting Inspired
>> Fresh Trends
>> Screen Resolution
... ... ... ... ... ... ... ... ... ...... ... ... ... ... ... ... ... ... ... ... and so many tricky things.

You can have a look at the article right from below:-


Continue Reading...

zend certification preparation ::: Arrays and functions

June 30, 2009

It's been a long time since I am posting something about ZCE. Just because of enormous pressure of thesis work and office works .. i couldn't managed time for taking preparation.

However I am starting again now. I will now try to concentrate about php arrays and functions and try to find answers about some tricky questions.

  • In php a class is declared using the class construct

  • <?php
    class my_class
    {
    var $myVar;
    function my_class ($var)
    {
    $this->my_var = $var;
    }
    }
    ?>


  • Object is instantiated by
    $obj = new my_class (“something”);

  • So for previous class example
    $obj->my_var; 
    can fetch the value

  • For using any of the methods of the class, we can use "namespace" concept. Let us consider we have a class called 'myclass' and it has a method named calc(). So now to access the method we can use the following code:

    <?php
    class myclass
    {
    var $var1;
    function myclass ($value)
    {
    $this->var1 = $value;
    }

    function calc($val)
    {
    $val = pow($val,2);
    return $val;
    }
    }

    echo myclass::calc(16);
    ?>

    This code will yield 256.

  • A class is a blueprint of an object, which is an instance of a class.

  • Object-oriented pattern used to implement a class that must be instantiated only once for the entire lifespan of a script is ---- Singleton Pattern

  • Constructor that can be used for a class ---- in php5 both classname() and __classname() can be used. But in php4 only classname() is supported


  • In php4 the following code will output 5 as there objects are treated as scalar ways and copying object like "$b=$a" makes only another copy so the later assignment does not make sense.

    But in php5, the output will be 10.

    <?php
    class my_class
    {
    var $value;
    }
    $a = new my_class;
    $a->my_value = 5;
    $b = $a;
    $b->my_value = 10;
    echo $a->my_value;
    ?>


  • In php parent constructors are not automatically called from a child class’ constructor—they have to be executed explicitly. This is true of any other class member (variables etc.).

  • To sort an array in ascending order by value while preserving key
    associations the PHP sorting function in action will be --- "asort"

  • The name of a function used to convert an array into a string is --- "serialize" .... "implode" can also be used for this purpose

  • "natsort()" function uses a “natural ordering” algorithm to sort the contents of an array,rather than a simple binary comparison between the contents of each element

  • "array_flip()" swaps each element of the array with its index

  • "rsort()" and "array_reverse()" reorder an array in reverse order that is if we consider
    $a = array('x','y','z');
    as a reference,
    rsort($a);
    and
    array_reverse($a);
    gives us the same output which is
    array('z','y','x')

  • The "array_sum()" function calculates the sum of all the elements of an array.

  • Only integer numbers and strings can be used as keys of an array; floating point numbers are converted to integers like 1.2 and 1.5 as keys of and array will result the array as having only 1 element with key 1 and it will take the value of last index that is the the value of index 1.5


To be continued .... [until tomorrow :P]
Continue Reading...

Preparing Research Paper on "Information Security Management in Online Payment Systems" [Part -2]

May 31, 2009

In step 2, My task will be prepare a demo report keeping the format of a final report and show it to the supervisor for approval. The later events are not possible to put in this article. I will focus on the preparing demo report.

Identifying the key chapters:::
(1.) Letter of Transmittal
(2.) Supervisor's certification
(3.) Acknowledgment
(4.) Executive Summary
(5.) Literature Review
(6.) Data and Analysis
(7.) Findings and Summary
(8.) Recommendations and Conclusion
(9.) References and Conclusion
(10.) Appnendix


In the Executive summary part, I described shortly how a online payment system is similar to everyday buying and selling and then where and how the problems occur. I put the basic finidings of our study here to enrich the executive summary which are --

(a) Lack of consciousness of secure and non-secure connection

(b) Lack of consciousness about up gradation of technology in course of time

(c) Lack of knowledge in choosing popular payment gateways

(d) Carelessness while clicking any link

(e) Visiting Scam sites (which can install malware in user pc)

(f) Lack of security while configuring payment gateway

(g) Above all, putting malicious third party content in the web lessens security of that site.



In literature review chap 1, I have written sub-topics like
>> Introduction >> Scope of the study >> objectives >> Methodology >> Limitation of the study.

In chap 2 , i am discussing about different payment gateways (4 mainly - paypal, authorize dot net, google checkout and 2 checkout) - their flow, merits, flaws, poplarity etc [Chap Name -- payment gateway benchmarks].

in chap 3, i will consider theory of info secu management to relate them here.

In chap 4, i am discussing security articles fromdifferent journals and find out some ocommon scenario to analyze them.

In chap 5, perspective bangladesh

In chap 6, Data collection [primary and secondary] and analysis

In chap 7, Findings and Summary

In chap 8, recomendation for common people usage, for administratiors, for decisionmakersof bangladesh.

In chap 9, all the referneces and colcusions

In chap 10, appendix


In my next post I will provide the complete view of the paper and provide download links for paper.

So loooonnnnngggggggg <3
Continue Reading...
 
Wave! | Profile