質問編集履歴

5

セキュリティの関わる問題なので削除させていただきました。

2018/06/18 10:52

投稿

amaguri
amaguri

スコア227

test CHANGED
@@ -1 +1 @@
1
- cakePHP if文common.phpを使う
1
+ セキュリティの関わる問題なの削除させていただきました。
test CHANGED
@@ -1,151 +1 @@
1
- 接続元IPをgetAccessIpで取得し、そのIPがallow_ipsに登録されているIPレンジかの判断をGetAllowIPsByAccessIpで行っています。
2
-
3
- それの結果に対しての処理を
4
-
5
- if(empty($ips)){}
6
-
7
- で行っています。
8
-
9
- ```ここに言語を入力
10
-
11
- controller
12
-
13
- $ips=CommonComponent::GetAllowIPsByAccessIp();
14
-
15
- if(empty($ips)){
16
-
17
- $conditions=array("findate is null",'private_flg' => 0);
18
-
19
- }
20
-
21
- ```
22
-
23
- ```ここに言語を入力
24
-
25
- common.php
26
-
27
- function GetAllowIPsByAccessIp(){
28
-
29
- $access_ip = CommonComponent::getAccessIp();
30
-
31
- $this->loadModel('AllowIps');
32
-
33
- $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)";
34
-
35
- $ips =$this->AllowIps->query($sql,array($access_ip));
36
-
37
- //$ips=$this->AllowIps->find('all');
38
-
39
- return $ips;
40
-
41
- }
42
-
43
-
44
-
45
- function getAccessIp() {
46
-
47
- if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
48
-
49
- return $_SERVER['REMOTE_ADDR'];
50
-
51
- }
52
-
53
-
54
-
55
- $ips = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
56
-
57
- return trim(end($ips));
58
-
59
- }
60
-
61
-
62
-
63
- ```
64
-
65
-
66
-
67
- 今回controller内
68
-
69
- $ips=CommonComponent::GetAllowIPsByAccessIp();
70
-
71
- if(empty($ips)){}
72
-
73
- のコードの処理をcommon.phpに記載をしてbooleanで有効か無効かの判定をし、それをif文で切り分けしたいと思っています。
74
-
75
-
76
-
77
- ```ここに言語を入力
78
-
79
- common.php
80
-
81
- function CanAccessPrivateDB(){
82
-
83
- $ips=CommonComponent::GetAllowIPsByAccessIp();
84
-
85
- if(empty($ips)){
86
-
87
- $private_flg=0;
88
-
89
- }else{
90
-
91
- $private_flg=1;
92
-
93
- }
94
-
95
- return $private_flg;
96
-
97
- }
98
-
99
- ```
100
-
101
- ```ここに言語を入力
102
-
103
- controller
104
-
105
- if(CommonComponent::CanAccessPrivateDB()==FALSE){
106
-
107
- $conditions=array("findate is null",'private_flg' => 0);
108
-
109
- }
110
-
111
- ```
112
-
113
- ようにかいてみたのですが動てくれせん
1
+ セキュリティ関わる問題なので削除させてただきした
114
-
115
- 何は原因でしょうか?
116
-
117
- やりたい動きとしては
118
-
119
- if(CommonComponent::CanAccessPrivateDB()==FALSE)
120
-
121
-
122
-
123
- if($private_flgが0の時)
124
-
125
-
126
-
127
- if(CommonComponent::CanAccessPrivateDB())
128
-
129
-
130
-
131
- if($private_flgが1の時)
132
-
133
- のように動作をしたいと考えています。
134
-
135
-
136
-
137
-
138
-
139
- 追記
140
-
141
- ```ここに言語を入力
142
-
143
- if(CommonComponent::CanAccessPrivateDB()==0)
144
-
145
-
146
-
147
- if(CommonComponent::CanAccessPrivateDB()==1)
148
-
149
- の場合は動きます
150
-
151
- ```

4

切り分け追加

2018/06/18 10:52

投稿

amaguri
amaguri

スコア227

test CHANGED
File without changes
test CHANGED
@@ -131,3 +131,21 @@
131
131
  if($private_flgが1の時)
132
132
 
133
133
  のように動作をしたいと考えています。
134
+
135
+
136
+
137
+
138
+
139
+ 追記
140
+
141
+ ```ここに言語を入力
142
+
143
+ if(CommonComponent::CanAccessPrivateDB()==0)
144
+
145
+
146
+
147
+ if(CommonComponent::CanAccessPrivateDB()==1)
148
+
149
+ の場合は動きます
150
+
151
+ ```

3

syuusei

2016/09/21 05:21

投稿

amaguri
amaguri

スコア227

test CHANGED
File without changes
test CHANGED
@@ -100,6 +100,8 @@
100
100
 
101
101
  ```ここに言語を入力
102
102
 
103
+ controller
104
+
103
105
  if(CommonComponent::CanAccessPrivateDB()==FALSE){
104
106
 
105
107
  $conditions=array("findate is null",'private_flg' => 0);

2

修正

2016/09/21 05:12

投稿

amaguri
amaguri

スコア227

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  それの結果に対しての処理を
4
4
 
5
- f(empty($ips)){}
5
+ if(empty($ips)){}
6
6
 
7
7
  で行っています。
8
8
 

1

やりたいことの追加

2016/09/21 05:10

投稿

amaguri
amaguri

スコア227

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,11 @@
1
+ 接続元IPをgetAccessIpで取得し、そのIPがallow_ipsに登録されているIPレンジかの判断をGetAllowIPsByAccessIpで行っています。
2
+
3
+ それの結果に対しての処理を
4
+
5
+ f(empty($ips)){}
6
+
7
+ で行っています。
8
+
1
9
  ```ここに言語を入力
2
10
 
3
11
  controller
@@ -56,7 +64,15 @@
56
64
 
57
65
 
58
66
 
59
- これ
67
+ 今回controller内
68
+
69
+ $ips=CommonComponent::GetAllowIPsByAccessIp();
70
+
71
+ if(empty($ips)){}
72
+
73
+ のコードの処理をcommon.phpに記載をしてbooleanで有効か無効かの判定をし、それをif文で切り分けしたいと思っています。
74
+
75
+
60
76
 
61
77
  ```ここに言語を入力
62
78
 
@@ -92,6 +108,24 @@
92
108
 
93
109
  ```
94
110
 
95
- と(boolean)を使ってかいてみたのですが動いてくれません。
111
+ このようにかいてみたのですが動いてくれません。
96
112
 
97
113
  何は原因でしょうか?
114
+
115
+ やりたい動きとしては
116
+
117
+ if(CommonComponent::CanAccessPrivateDB()==FALSE)
118
+
119
+
120
+
121
+ if($private_flgが0の時)
122
+
123
+
124
+
125
+ if(CommonComponent::CanAccessPrivateDB())
126
+
127
+
128
+
129
+ if($private_flgが1の時)
130
+
131
+ のように動作をしたいと考えています。