File: restrict.ip.inc

Recommend this page to a friend!
  Classes of Ovidiu Bokar  >  IP Restriction  >  restrict.ip.inc  >  Download  
File: restrict.ip.inc
Role: Class source
Content type: text/plain
Description: IP restriction class
Class: IP Restriction
Check a given IP against a list of allowed IPs
Author: By
Last change: removed unneeded comments
Date: 5 years ago
Size: 1,035 bytes
 

Contents

Class file image Download
<?php
/**
 * @file
 *
 * @copyright Copyright (C) 2015 OSb Web Solutions
 * @author Ovidiu S Bokar <contact@osbwebsolutions.com>
 * @date 25/02/2015
 *
 */
class Restriction {

   
/**
     * @var
     */
   
private $_allowedIPList;
   
/**
     * @var
     */
   
private $_userIP;

   
/**
     * @param $arg
     * @return mixed
     */
   
public function getAllowedIPlist($arg){
        return
$this->_allowedIPList = $arg["allowed"];
    }

   
/**
     * @param $ip
     * @return mixed
     */
   
public function getUserIP($ip){
        return
$this->_userIP = $ip;
    }

   
//check if the user IP is in the white list
    /**
     *
     */
   
public function checkGlobalIndex(){
        if(!
in_array($this->_userIP,$this->_allowedIPList)){
            echo
'You are in the wrong place.';exit;
        }
    }

   
/**
     * @param $arg
     * @param $ip
     */
   
public function globalInit($whiteList,$ip){
       
$this->getAllowedIPlist($whiteList);
       
$this->getUserIP($ip);
       
$this->checkGlobalIndex();
    }
}


For more information send a message to info at phpclasses dot org.