PHP code example of kaleidpixel / geoipallow

1. Go to this page and download the library: Download kaleidpixel/geoipallow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaleidpixel / geoipallow example snippets



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 );
	}
}



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);

shell
$ php ./example/index.php