geocoder-php/stack-geo-ip 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geocoder-php/stack-geo-ip

Composer 安装命令:

composer require geocoder-php/stack-geo-ip

包简介

Geolocation Stack middleware for Geocoder library.

README 文档

README

Geolocation Stack middleware that adds geolocation results to the request for subsequent middlewares by leveraging the Geocoder library.

Build Status

Usage

Example

Here we create a simple application that returns the IP address of the request and the contents of the X-Country header to the browser. Normally, the X-Country header would not exists.

By wrapping the GeoIP middleware around it using the StackBuilder, if the IP address can be matched to a country, the X-Country header will be set to the two-letter code for that country, and be available to the application.

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

require __DIR__ . '/vendor/autoload.php';

$app = new \Silex\Application();

$app->get('/', function(Request $request) {
    $ip      = $request->getClientIp();
    $country = $request->headers->get('X-Country', 'UNKNOWN');

    return new Response($ip . ' => '. $country, 200);
});

$stack = (new \Stack\Builder())
    ->push('Geocoder\Stack\GeoIp')
    ;

$app = $stack->resolve($app);

$request  = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);

Options

The following options can be used:

  • adapter (optional): The Geocoder HTTP adapter to use. Defaults to cURL adapter.

  • provider (optional): The Geocoder provider to use. Defaults to the FreeGeoIP provider. For production, it is recommended to use a provider that relies on local files rather than HTTP requests, such as Max Mind binary provider.

  • header (optional): The name of the HTTP header to store the country result in. Defaults to "X-Country".

See the Geocoder documentation for a list of available adapters and providers.

Intallation

The recommended way to install StackGeoIp is through Composer:

{
    "require": {
        "geocoder-php/stack-geo-ip": "@stable"
    }
}

Protip: you should browse the geocoder-php/stack-geo-ip page to choose a stable version to use, avoid the @stable meta constraint.

License

StackGeoIp is released under the MIT License. See the bundled LICENSE file for details.

统计信息

  • 总下载量: 425
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 40
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 5
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-09-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固