Torann / laravel-geoip

Determine the geographical location of website visitors based on their IP addresses.
http://lyften.com/projects/laravel-geoip
BSD 2-Clause "Simplified" License
2.09k stars 372 forks source link

Updating local continent database - 301 Moved Permanently #102

Closed rjp2525 closed 5 years ago

rjp2525 commented 6 years ago

Visiting the link used for updating the local continent data in the browser will download the country_continent.csv file, but running php artisan geoip:update leaves an empty array within continents.json in the app storage folder. Debugging and retrieving the output returns a 301 Moved Permanently response from maxmind:

[
    "<html><head><title>301 Moved Permanently<\/title><\/head>\r\n<body bgcolor=\"white\">\r\n<center><h1>301 Moved Permanently<\/h1><\/center>\r\n<hr><center>nginx<\/center>\r\n<\/body>\r\n<\/html>\r\n",
    {
        "0":"HTTP\/1.1 301 Moved Permanently",
        "Server":"nginx",
        "Date":"Sun, 25 Feb 2018 20:16:06 GMT",
        "Content-Type":"text\/html",
        "Content-Length":"178",
        "Connection":"keep-alive",
        "Keep-Alive":"timeout=20",
        "Location":"https:\/\/dev.maxmind.com\/static\/csv\/codes\/country_continent.csv",
        "X-Type":"default",
        "1":"",
        "2":""
    }
]
rjp2525 commented 6 years ago

I was able to fix within a custom service by using file_get_contents rather than $this->client->get() and changing $lines = explode("\n", $data[0]); to $lines = explode("\n", $data);:

public function update()
{
    $data = file_get_contents('http://dev.maxmind.com/static/csv/codes/country_continent.csv');

    // Verify server response
    if ($this->client->getErrors() !== null) {
        throw new Exception($this->client->getErrors());
    }

    $lines = explode("\n", $data);

    array_shift($lines);

    ....
}
Torann commented 5 years ago

The download file for this is in the config file