1. Go to this page and download the library: Download coosos/ip-filter-bundle 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/ */
// src/Entity/Ip.php
namespace App\Entity;
use Coosos\IpFilterBundle\Entity\Ip as BaseIp;
use Doctrine\ORM\Mapping as ORM;
/**
* Ip
*
* @ORM\Table(name="ips")
*/
class Ip extends BaseIp
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function getId()
{
return $this->id;
}
}
use Coosos\IpFilterBundle\Model\IpManagerInterface;
/** @var IpManagerInterface $ipManager */
$ipManager = $this->container->get('sl_ip_filter.ip_manager'); //Use this line, even if you use a custom IP manager
//Create your IP
$ip = $ipManager->createIp();
$ip->setStartIp('192.168.1.10') // Use only setStartIp() if it's a simple IP
->setEnvironment(['dev', 'test']) // You can also use 'prod'
->setAuthorized(false);
$ipManager->saveIp($ip);
// If you need to block or authorized an IP range, you must also specify an end ip with the setEndIp() method
$ip = $ipManager->createIp();
$ip->setStartIp('10.30.0.0')
->setEndIp('10.30.0.255')
->setEnvironment(['dev', 'test'])
->setAuthorized(true);
$ipManager->saveIp($ip);