Monday, June 27, 2011

get user city location

Create function in your controller file..

<?php
function _get_location()
    {
        $country=file_get_contents('http://api.hostip.info/get_html.php?ip=');
        $_country = explode ("\n", $country);
        $_country = str_replace("City: ", "", $_country);
        return $_country[1];
    }
?>


and call this function like this in your controller.

<?php echo $this->_get_location(); ?>

This will give user's location based on its IP address.

No comments:

Post a Comment