定制 kaleidpixel/geoipallow 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kaleidpixel/geoipallow

Composer 安装命令:

composer require kaleidpixel/geoipallow

包简介

A streamlined tool designed to generate .htaccess configurations, allowing web access exclusively from IP addresses of a specified country. Enhance your site's security and target your audience more effectively.

README 文档

README

A streamlined tool designed to generate .htaccess configurations, allowing web access exclusively from IP addresses of a specified country. Enhance your site's security and target your audience more effectively.

Document

Coding is quite simple. The options are only simple, so you won't get lost.

Options

Option Description
server
default: apache
Apache or Nginx
ipv
default: 0
Specify the version of the IP Address with a single digit (4 or 6).
country
default: US
Specify the name of the country using the ISO code (Alpha-2 code) as defined in the ISO 3166 international standard.
output_path
default: empty
File path including the name of the file to output the results.
add_before_str
default: empty
.
add_after_str
default: empty
.

Methods

Method Parameter Description
read() bool $echo = false
bool $force = false
Create a list of IP addresses. If already created, cache it for one day.
delete() none Delete the IP address added with the read method.
ipListEndPoints() none Wrapper method for the constant IP_LIST_ENDPOINTS.
getCIDRRangeIPv4() int $range = 0 Calculate CIDR.
is_cli() none Check if the type of interface between the web server and PHP is CLI.
curl_get_content() string $url = ''
array $header = []
string $method = 'GET'
array $data = []
Retrieve the HTTP code and content of the specified URL.
download() string $file_path = ''
string $mime_type = null
Output the header in the web browser to download the file and initiate the file download.

Basic markup

What follows is the simplest coding.

Example 1

<?php
namespace exampleproject;

use kaleidpixel\GeoIPAllow;

class JPIPAllow {
	/**
	 * @var GeoIPAllow
	 */
	protected $geoIpAllow = null;

	public function __construct( array $setting = [] ) {
		$setting['country'] = 'JP';

		if ( empty( $setting['output_path'] ) ) {
			$setting['output_path'] = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . '.htaccess';
		}

		$this->geoIpAllow = new GeoIPAllow( $setting );
	}

	/**
	 * @param bool $echo
	 * @param bool $force
	 *
	 * @return void
	 */
	public function read( bool $echo = false, bool $force = false ): void {
		$this->geoIpAllow->read( $echo, $force );
	}
}

Example 2

<?php
require_once dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

use kaleidpixel\GeoIPAllow;

$now        = date( 'Y-m-d' );
$before_str = <<<EOL
## IP address of its In-House server.
Allow from 103.xxx.xxx.xxx
Allow from 203.xxx.xxx.xxx
EOL;

$ip = new GeoIPAllow(
	[
		'server'         => 'apache',
		'country'        => 'JP',
		'output_path'    => __DIR__ . DIRECTORY_SEPARATOR . '.htaccess',
		'add_before_str' => $before_str
	]
);

$ip->read(true);

The source code shown above will work on the built-in web server. It also operates in CLI, so choose whichever you prefer.

If you want to run it on the built-in web server, execute the command shown below and then access it with a web browser.

$ php -S localhost:8080

If you want to run it in CLI, execute the command shown below. The path where the file is outputted will be displayed as a result.

$ php ./example/index.php

License

MIT License
Copyright (c) 2023 Kaleid Pixel

kaleidpixel/geoipallow 适用场景与选型建议

kaleidpixel/geoipallow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 kaleidpixel/geoipallow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kaleidpixel/geoipallow 我们能提供哪些服务?
定制开发 / 二次开发

基于 kaleidpixel/geoipallow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-04