接続元IPをgetAccessIpで取得し、そのIPがallow_ipsに登録されているIPレンジかの判断をGetAllowIPsByAccessIpで行っています。
それの結果に対しての処理を
if(empty($ips)){}
で行っています。
controller
$ips=CommonComponent::GetAllowIPsByAccessIp();
if(empty($ips)){
$conditions=array("findate is null",'private_flg' => 0);
}
common.php
function GetAllowIPsByAccessIp(){
$access_ip = CommonComponent::getAccessIp();
$this->loadModel('AllowIps');
$sql = "SELECT start_ip, last_ip, full_access_flg FROM allow_ips AS AllowIps WHERE INET_ATON(?) between INET_ATON(start_ip) and INET_ATON(last_ip)";
$ips =$this->AllowIps->query($sql,array($access_ip));
//$ips=$this->AllowIps->find('all');
return $ips;
}
function getAccessIp() {
if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['REMOTE_ADDR'];
}
$ips = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim(end($ips));
}
今回controller内
$ips=CommonComponent::GetAllowIPsByAccessIp();
if(empty($ips)){}
のコードの処理をcommon.phpに記載をしてbooleanで有効か無効かの判定をし、それをif文で切り分けしたいと思っています。
common.php
function CanAccessPrivateDB(){
$ips=CommonComponent::GetAllowIPsByAccessIp();
if(empty($ips)){
$private_flg=0;
}else{
$private_flg=1;
}
return $private_flg;
}
controller
if(CommonComponent::CanAccessPrivateDB()==FALSE){
$conditions=array("findate is null",'private_flg' => 0);
}
このようにかいてみたのですが動いてくれません。
何は原因でしょうか?
やりたい動きとしては
if(CommonComponent::CanAccessPrivateDB()==FALSE)
は
if($private_flgが0の時)
if(CommonComponent::CanAccessPrivateDB())
は
if($private_flgが1の時)
のように動作をしたいと考えています。
追記
if(CommonComponent::CanAccessPrivateDB()==0)
if(CommonComponent::CanAccessPrivateDB()==1)
の場合は動きます