| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 845 |
liveuser |
6 |
Copyright (C) 2015~2025 Min-Jhin,Chen
|
| 1 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
| 249 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
用於驗證處理的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class authenticate{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
103 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#$result["error"],錯誤訊息陣列.
|
|
|
106 |
#必填參數:
|
|
|
107 |
$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
108 |
#可省略參數:
|
|
|
109 |
#無.
|
| 169 |
liveuser |
110 |
#參考資料:
|
|
|
111 |
#無.
|
| 1 |
liveuser |
112 |
#備註:
|
|
|
113 |
#無.
|
|
|
114 |
*/
|
|
|
115 |
public static function simpleAuthenticate(&$conf){
|
|
|
116 |
|
|
|
117 |
#初始化要回傳的變數
|
|
|
118 |
$result=array();
|
|
|
119 |
|
|
|
120 |
#記錄當前執行的函數名稱
|
|
|
121 |
$result["function"]=__FUNCTION__;
|
|
|
122 |
|
|
|
123 |
#如果 $conf 不為陣列
|
|
|
124 |
if(gettype($conf)!="array"){
|
|
|
125 |
|
|
|
126 |
#設置執行失敗
|
|
|
127 |
$result["status"]="false";
|
|
|
128 |
|
|
|
129 |
#設置執行錯誤訊息
|
|
|
130 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
131 |
|
|
|
132 |
#如果傳入的參數為 null
|
|
|
133 |
if($conf==null){
|
|
|
134 |
|
|
|
135 |
#設置執行錯誤訊息
|
|
|
136 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
137 |
|
|
|
138 |
}#if end
|
|
|
139 |
|
|
|
140 |
#回傳結果
|
|
|
141 |
return $result;
|
|
|
142 |
|
|
|
143 |
}#if end
|
|
|
144 |
|
|
|
145 |
#檢查參數
|
|
|
146 |
#函式說明:
|
|
|
147 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
148 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
149 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
150 |
#$result["function"],當前執行的函式名稱.
|
|
|
151 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
152 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
153 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
154 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
155 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
156 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
157 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
158 |
#必填參數:
|
|
|
159 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
160 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
161 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
162 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("password");
|
|
|
163 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
164 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
165 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
166 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
167 |
#可以省略的參數:
|
|
|
168 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
169 |
#$conf["canBeEmptyString"]="false";
|
|
|
170 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
171 |
#$conf["skipableVariableName"]=array();
|
|
|
172 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
173 |
#$conf["skipableVariableType"]=array();
|
|
|
174 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
175 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
176 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
177 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
178 |
#參考資料來源:
|
|
|
179 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
180 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
181 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
182 |
|
|
|
183 |
#debug
|
|
|
184 |
#var_dump($checkResult);
|
|
|
185 |
#exit;
|
|
|
186 |
|
|
|
187 |
#debug
|
|
|
188 |
#var_dump($result);
|
|
|
189 |
#exit;
|
|
|
190 |
|
|
|
191 |
#如果檢查失敗
|
|
|
192 |
if($checkResult["status"]=="false"){
|
|
|
193 |
|
|
|
194 |
#debug
|
|
|
195 |
#var_dump($result);
|
|
|
196 |
#exit;
|
|
|
197 |
|
|
|
198 |
#debug
|
|
|
199 |
#var_dump($checkResult);
|
|
|
200 |
#exit;
|
|
|
201 |
|
|
|
202 |
#設置執行失敗
|
|
|
203 |
$result["status"]="false";
|
|
|
204 |
|
|
|
205 |
#設置執行錯誤訊息
|
|
|
206 |
$result["error"]=$checkResult;
|
|
|
207 |
|
|
|
208 |
#回傳結果
|
|
|
209 |
return $result;
|
|
|
210 |
|
|
|
211 |
}#if end
|
|
|
212 |
|
|
|
213 |
#如果檢查不通過
|
|
|
214 |
if($checkResult["passed"]=="false"){
|
|
|
215 |
|
|
|
216 |
#設置執行失敗
|
|
|
217 |
$result["status"]="false";
|
|
|
218 |
|
|
|
219 |
#設置執行錯誤訊息
|
|
|
220 |
$result["error"]=$checkResult;
|
|
|
221 |
|
|
|
222 |
#回傳結果
|
|
|
223 |
return $result;
|
|
|
224 |
|
|
|
225 |
}#if end
|
|
|
226 |
|
|
|
227 |
#debug
|
|
|
228 |
#var_dump($result);
|
|
|
229 |
#exit;
|
|
|
230 |
|
|
|
231 |
#echo "entered";
|
|
|
232 |
|
|
|
233 |
#若沒有供驗證的變數,或其驗證內容爲""
|
| 51 |
liveuser |
234 |
if(!isset($_SESSION['password']) || $_SESSION['password']===""){
|
| 1 |
liveuser |
235 |
|
|
|
236 |
#設置執行成功
|
|
|
237 |
$result["status"]="true";
|
|
|
238 |
|
|
|
239 |
#設置驗證不通過
|
|
|
240 |
$result["passed"]="false";
|
|
|
241 |
|
|
|
242 |
#回傳結果
|
|
|
243 |
return $result;
|
|
|
244 |
|
|
|
245 |
}#if end
|
|
|
246 |
|
|
|
247 |
#如果驗證碼不正確
|
| 51 |
liveuser |
248 |
if($_SESSION['password']!==$conf["password"]){
|
| 1 |
liveuser |
249 |
|
|
|
250 |
#設置執行成功
|
|
|
251 |
$result["status"]="true";
|
|
|
252 |
|
|
|
253 |
#設置驗證不通過
|
|
|
254 |
$result["passed"]="false";
|
|
|
255 |
|
|
|
256 |
#回傳結果
|
|
|
257 |
return $result;
|
|
|
258 |
|
|
|
259 |
}#if end
|
|
|
260 |
|
|
|
261 |
#反之驗證成功
|
|
|
262 |
else{
|
|
|
263 |
|
|
|
264 |
#設置執行成功
|
|
|
265 |
$result["status"]="true";
|
|
|
266 |
|
|
|
267 |
#設置驗證通過
|
|
|
268 |
$result["passed"]="true";
|
|
|
269 |
|
|
|
270 |
#回傳結果
|
|
|
271 |
return $result;
|
|
|
272 |
|
|
|
273 |
}#else end
|
|
|
274 |
|
|
|
275 |
#不應該執行到這邊
|
|
|
276 |
#設置執行失敗
|
|
|
277 |
$result["status"]="false";
|
|
|
278 |
|
|
|
279 |
#設置驗證不通過
|
|
|
280 |
$result["passed"]="false";
|
|
|
281 |
|
|
|
282 |
#回傳結果
|
|
|
283 |
return $result;
|
|
|
284 |
|
|
|
285 |
}#函式結束
|
|
|
286 |
|
|
|
287 |
/*
|
|
|
288 |
#函式說明:
|
|
|
289 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確,如果檢查不通過,則會轉址.
|
|
|
290 |
#回傳結果:
|
|
|
291 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
292 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
293 |
#$result["function"],當前執行的函數名稱.
|
|
|
294 |
#必填參數:
|
|
|
295 |
$conf["failLocation"]="";#是當驗證失敗時要轉址到的位置
|
|
|
296 |
$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
297 |
#可省略參數:
|
|
|
298 |
#無.
|
| 170 |
liveuser |
299 |
#參考資料:
|
|
|
300 |
#無.
|
| 1 |
liveuser |
301 |
#備註:
|
|
|
302 |
#無.
|
|
|
303 |
*/
|
|
|
304 |
public static function sessionAuthenticate(&$conf){
|
|
|
305 |
|
|
|
306 |
#初始化要回傳的變數
|
|
|
307 |
$result=array();
|
|
|
308 |
|
|
|
309 |
#記錄當前執行的函數名稱
|
|
|
310 |
$result["function"]=__FUNCTION__;
|
|
|
311 |
|
|
|
312 |
#如果 $conf 不為陣列
|
|
|
313 |
if(gettype($conf)!="array"){
|
|
|
314 |
|
|
|
315 |
#設置執行失敗
|
|
|
316 |
$result["status"]="false";
|
|
|
317 |
|
|
|
318 |
#設置執行錯誤訊息
|
|
|
319 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
320 |
|
|
|
321 |
#如果傳入的參數為 null
|
|
|
322 |
if($conf==null){
|
|
|
323 |
|
|
|
324 |
#設置執行錯誤訊息
|
|
|
325 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
326 |
|
|
|
327 |
}#if end
|
|
|
328 |
|
|
|
329 |
#回傳結果
|
|
|
330 |
return $result;
|
|
|
331 |
|
|
|
332 |
}#if end
|
|
|
333 |
|
|
|
334 |
#檢查參數
|
|
|
335 |
#函式說明:
|
|
|
336 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
337 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
338 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
339 |
#$result["function"],當前執行的函式名稱.
|
|
|
340 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
341 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
342 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
343 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
344 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
345 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
346 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
347 |
#必填參數:
|
|
|
348 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
349 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
350 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
351 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("failLocation","password");
|
|
|
352 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
353 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
354 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
355 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
356 |
#可以省略的參數:
|
|
|
357 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
358 |
#$conf["canBeEmptyString"]="false";
|
|
|
359 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
360 |
#$conf["skipableVariableName"]=array();
|
|
|
361 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
362 |
#$conf["skipableVariableType"]=array();
|
|
|
363 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
364 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
365 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
366 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
367 |
#參考資料來源:
|
|
|
368 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
369 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
370 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
371 |
|
|
|
372 |
#如果檢查失敗
|
|
|
373 |
if($checkResult["status"]=="false"){
|
|
|
374 |
|
|
|
375 |
#設置執行失敗
|
|
|
376 |
$result["status"]="false";
|
|
|
377 |
|
|
|
378 |
#設置執行錯誤訊息
|
|
|
379 |
$result["error"]=$checkResult;
|
|
|
380 |
|
|
|
381 |
#回傳結果
|
|
|
382 |
return $result;
|
|
|
383 |
|
|
|
384 |
}#if end
|
|
|
385 |
|
|
|
386 |
#如果檢查不通過
|
|
|
387 |
if($checkResult["status"]=="false"){
|
|
|
388 |
|
|
|
389 |
#設置執行失敗
|
|
|
390 |
$result["status"]="false";
|
|
|
391 |
|
|
|
392 |
#設置執行錯誤訊息
|
|
|
393 |
$result["error"]=$checkResult;
|
|
|
394 |
|
|
|
395 |
#回傳結果
|
|
|
396 |
return $result;
|
|
|
397 |
|
|
|
398 |
}#if end
|
|
|
399 |
|
|
|
400 |
#取得驗證碼驗證的回傳值
|
|
|
401 |
#函式說明:
|
|
|
402 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
403 |
#回傳結果:
|
|
|
404 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
405 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
406 |
#$result["function"],當前執行的函數名稱.
|
|
|
407 |
#$result["error"],錯誤訊息陣列.
|
|
|
408 |
#必填參數:
|
|
|
409 |
$conf["authenticate::simpleAuthenticate"]["password"]=$conf["password"];#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
410 |
$simpleAuthenticate=authenticate::simpleAuthenticate($conf["authenticate::simpleAuthenticate"]);
|
|
|
411 |
unset($conf["authenticate::simpleAuthenticate"]);
|
|
|
412 |
|
|
|
413 |
#如果執行驗證失敗
|
|
|
414 |
if($simpleAuthenticate["status"]=="false"){
|
|
|
415 |
|
|
|
416 |
#設置執行失敗
|
|
|
417 |
$result["status"]="false";
|
|
|
418 |
|
|
|
419 |
#設置錯誤訊息
|
|
|
420 |
$result["error"]=$simpleAuthenticate;
|
|
|
421 |
|
|
|
422 |
#回傳結果
|
|
|
423 |
return $result;
|
|
|
424 |
|
|
|
425 |
}#if end
|
|
|
426 |
|
|
|
427 |
#如果驗證失敗
|
|
|
428 |
if($simpleAuthenticate["passed"]=="false"){
|
|
|
429 |
|
|
|
430 |
#進行轉址
|
|
|
431 |
#函式說明:
|
|
|
432 |
#設定session變數後,立即轉址.
|
|
|
433 |
#回傳的結果:
|
|
|
434 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
435 |
#$result["error"],錯誤訊息陣列.
|
|
|
436 |
#必填的參數:
|
|
|
437 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
438 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
|
|
|
439 |
#可省略的參數:
|
|
|
440 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
441 |
#$conf["sessionName"]=array("");
|
|
|
442 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
443 |
#$conf["sessionValue"]=array("");
|
|
|
444 |
#參靠資料來源:
|
|
|
445 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
446 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
447 |
unset($conf["header::redirectionNow"]);
|
|
|
448 |
|
|
|
449 |
#如果轉址失敗
|
|
|
450 |
if($redirectionNow["status"]=="false"){
|
|
|
451 |
|
|
|
452 |
#設置執行失敗
|
|
|
453 |
$result["status"]="false";
|
|
|
454 |
|
|
|
455 |
#設置錯誤訊息
|
|
|
456 |
$result["error"]=$redirectionNow;
|
|
|
457 |
|
|
|
458 |
#回傳結果
|
|
|
459 |
return $result;
|
|
|
460 |
|
|
|
461 |
}#if end
|
|
|
462 |
|
|
|
463 |
}#if end
|
|
|
464 |
|
|
|
465 |
#執行到這邊代表正常
|
|
|
466 |
#設置執行正常
|
|
|
467 |
$result["status"]="true";
|
|
|
468 |
|
|
|
469 |
#回傳結果
|
|
|
470 |
return $result;
|
|
|
471 |
|
|
|
472 |
}#函式結束
|
|
|
473 |
|
|
|
474 |
/*
|
|
|
475 |
#函式說明:
|
|
|
476 |
#檢查session裏面的使用者$_SESSION["account"]是否在會員清單裏面,與該會員所屬的羣組是否具有權限瀏覽該子功能頁面.
|
|
|
477 |
#回傳的參數:
|
|
|
478 |
#$result["status"],執行是否正常的識別,"true"代表一切正常,"false"代表不正常
|
|
|
479 |
#$result["error"],錯誤訊息
|
|
|
480 |
#$result["function"],當前執行的函數名稱
|
|
|
481 |
#$result["passed"],是否通過檢查,"true"代表通過檢查,"false"代表沒有通過檢查.
|
|
|
482 |
#$result["warning"],記錄不會影響程式執行,但是需要注意的事情。
|
|
|
483 |
#$result["sql"],查詢用的sql.
|
|
|
484 |
#必填參數:
|
|
|
485 |
$conf["thisSubSystemName"]="";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
|
|
|
486 |
$conf["dbName"]="";#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
487 |
$conf["dbPassword"]="";#爲連線到資料庫時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
488 |
#可省略參數:
|
|
|
489 |
#$conf["dbAddress"]="localhost";#爲資料庫的位置,預設爲 "localhost"
|
|
|
490 |
#$conf["dbAccount"]="root";#爲用於連入資料庫時要使用的帳號,預設爲 "root"
|
|
|
491 |
#$conf["dtName.member"]="member";#儲存會員資料的資料表,預設爲 "member"
|
|
|
492 |
#$conf["dtName.userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
|
| 171 |
liveuser |
493 |
#參考資料:
|
|
|
494 |
#無.
|
| 1 |
liveuser |
495 |
#備註:
|
|
|
496 |
#無.
|
|
|
497 |
*/
|
|
|
498 |
public static function checkUserGroupAuthorities($conf){
|
|
|
499 |
|
|
|
500 |
#初始化要回傳的結果
|
|
|
501 |
$result=array();
|
|
|
502 |
|
|
|
503 |
#初始化儲存要回傳的警告訊息
|
|
|
504 |
$result["warning"]=array();
|
|
|
505 |
|
|
|
506 |
#記錄當前執行的涵式名稱
|
|
|
507 |
$result["function"]=__FUNCTION__;
|
|
|
508 |
|
|
|
509 |
#如果 $conf 不為陣列
|
|
|
510 |
if(gettype($conf)!="array"){
|
|
|
511 |
|
|
|
512 |
#設置執行失敗
|
|
|
513 |
$result["status"]="false";
|
|
|
514 |
|
|
|
515 |
#設置執行錯誤訊息
|
|
|
516 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
517 |
|
|
|
518 |
#如果傳入的參數為 null
|
|
|
519 |
if($conf==null){
|
|
|
520 |
|
|
|
521 |
#設置執行錯誤訊息
|
|
|
522 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
523 |
|
|
|
524 |
}#if end
|
|
|
525 |
|
|
|
526 |
#回傳結果
|
|
|
527 |
return $result;
|
|
|
528 |
|
|
|
529 |
}#if end
|
|
|
530 |
|
|
|
531 |
#檢查參數
|
|
|
532 |
#函式說明:
|
|
|
533 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
534 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
535 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
536 |
#$result["function"],當前執行的函式名稱.
|
|
|
537 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
538 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
539 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
540 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
541 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
542 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
543 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
544 |
#必填參數:
|
|
|
545 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
546 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
547 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
548 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("thisSubSystemName","dbName","dbPassword");
|
|
|
549 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
550 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
551 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
552 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
553 |
#可以省略的參數:
|
|
|
554 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
555 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
556 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
557 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbAddress","dbAccount","dtName.member","dtName.userGroup");
|
|
|
558 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
559 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
560 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
561 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("localhost","root","member","userGroupAuthorities");
|
|
|
562 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
563 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
564 |
#參考資料來源:
|
|
|
565 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
566 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
567 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
568 |
|
|
|
569 |
#如果 $checkResult["status"]=="false"
|
|
|
570 |
if($checkResult["status"]=="false"){
|
|
|
571 |
|
|
|
572 |
#設置執行不正常的適別
|
|
|
573 |
$result["status"]="false";
|
|
|
574 |
|
|
|
575 |
#設置執行錯誤的訊息
|
|
|
576 |
$result["error"]=$checkResult;
|
|
|
577 |
|
|
|
578 |
#回傳結果
|
|
|
579 |
return $result;
|
|
|
580 |
|
|
|
581 |
}#if end
|
|
|
582 |
|
|
|
583 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
584 |
if($checkResult["passed"]=="false"){
|
|
|
585 |
|
|
|
586 |
#設置執行不正常的適別
|
|
|
587 |
$result["status"]="false";
|
|
|
588 |
|
|
|
589 |
#設置執行錯誤的訊息
|
|
|
590 |
$result["error"]=$checkResult;
|
|
|
591 |
|
|
|
592 |
#回傳結果
|
|
|
593 |
return $result;
|
|
|
594 |
|
|
|
595 |
}#if end
|
|
|
596 |
|
|
|
597 |
#檢查是否有session["username"],如果不存在
|
|
|
598 |
if(!isset($_SESSION["username"])){
|
|
|
599 |
|
|
|
600 |
#設置執行正常的適別
|
|
|
601 |
$result["status"]="true";
|
|
|
602 |
|
|
|
603 |
#設置檢查不通過
|
|
|
604 |
$result["passed"]="false";
|
|
|
605 |
|
|
|
606 |
#設置警告訊息
|
|
|
607 |
$result["warning"][]="使用者名稱變數不存在";
|
|
|
608 |
|
|
|
609 |
#回傳結果
|
|
|
610 |
return $result;
|
|
|
611 |
|
|
|
612 |
}#if end
|
|
|
613 |
|
|
|
614 |
#檢查$_SESSION["username"]所屬的羣組爲何
|
|
|
615 |
|
|
|
616 |
#函式說明:
|
|
|
617 |
#一次取得資料庫、表的資料
|
|
|
618 |
#回傳的結果
|
|
|
619 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
620 |
#$result["error"],錯誤訊息陣列。
|
|
|
621 |
#$result["dataContent"],爲資料的內容。
|
|
|
622 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
623 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
624 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
625 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
626 |
#$result["sql"],執行的sql字串.
|
|
|
627 |
#必填參數:
|
|
|
628 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
629 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
630 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
|
|
|
631 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["dtName.member"];#爲要存取的資料表名稱
|
|
|
632 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array("account","groupName");#你想要的欄位!
|
|
|
633 |
#可省略參數:
|
|
|
634 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
635 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array("account");#用於判斷語句的欄位項目陣列。
|
|
|
636 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($_SESSION["account"]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
637 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
638 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
639 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
640 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
641 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
642 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
643 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
644 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
645 |
$memberData=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
646 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
647 |
|
|
|
648 |
#如果 $memberData["status"] 等於 "false"
|
|
|
649 |
if($memberData["status"]=="false"){
|
|
|
650 |
|
|
|
651 |
#設置執行不正常的適別
|
|
|
652 |
$result["status"]="false";
|
|
|
653 |
|
|
|
654 |
#設置執行錯誤的訊息
|
|
|
655 |
$result["error"]=$memberData;
|
|
|
656 |
|
|
|
657 |
#回傳結果
|
|
|
658 |
return $result;
|
|
|
659 |
|
|
|
660 |
}#if end
|
|
|
661 |
|
|
|
662 |
#如果 $memberData["dataCount"] 等於 0
|
|
|
663 |
if($memberData["dataCount"]==0){
|
|
|
664 |
|
|
|
665 |
#代表沒有符合的帳戶
|
|
|
666 |
$result["status"]="true";
|
|
|
667 |
|
|
|
668 |
#設置警告訊息
|
|
|
669 |
$result["warning"][]="使用者沒有歸屬於任何群組";
|
|
|
670 |
|
|
|
671 |
#紀錄查詢用的sql
|
|
|
672 |
$result["sql"]=$memberData["sql"];
|
|
|
673 |
|
|
|
674 |
#設置檢查不通過
|
|
|
675 |
$result["passed"]="false";
|
|
|
676 |
|
|
|
677 |
#回傳結果
|
|
|
678 |
return $result;
|
|
|
679 |
|
|
|
680 |
}#if end
|
|
|
681 |
|
|
|
682 |
#取得目前該使用者所屬的羣組
|
|
|
683 |
$userGroup=$memberData["dataContent"]["groupName"][0];#符合資料的會員群組名稱。
|
|
|
684 |
|
|
|
685 |
#檢查該群組能否瀏覽目標子系統
|
|
|
686 |
#函式說明:
|
|
|
687 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
688 |
#回傳的結果:
|
|
|
689 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
690 |
#$result["error"],錯誤訊息
|
|
|
691 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
692 |
#必填參數:
|
|
|
693 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
694 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
695 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
696 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["dtName.userGroup"];#欲選擇的資料表名稱
|
|
|
697 |
#可省略的參數:
|
|
|
698 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
699 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array("groupName","visitableSubSystem");#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
700 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($userGroup,$conf["thisSubSystemName"]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
701 |
$checkDataExistResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
702 |
unset($conf["db"]["checkDataExists"]);
|
|
|
703 |
|
|
|
704 |
#var_dump($checkDataExistResult);
|
|
|
705 |
|
|
|
706 |
#如果 $checkDataExistResult["status"] 等於 "false"
|
|
|
707 |
if($checkDataExistResult["status"]=="false"){
|
|
|
708 |
|
|
|
709 |
#代表操作失敗
|
|
|
710 |
$result["status"]="false";
|
|
|
711 |
|
|
|
712 |
#設置警告訊息
|
|
|
713 |
$result["error"]=$checkDataExistResult;
|
|
|
714 |
|
|
|
715 |
#回傳結果
|
|
|
716 |
return $result;
|
|
|
717 |
|
|
|
718 |
}#if end
|
|
|
719 |
|
|
|
720 |
#反之代表執行成功
|
|
|
721 |
else{
|
|
|
722 |
|
|
|
723 |
#如果 $checkDataExistResult["founded"] 等於 "true"
|
|
|
724 |
if($checkDataExistResult["founded"]=="true"){
|
|
|
725 |
|
|
|
726 |
#代表有相符合的資料
|
|
|
727 |
|
|
|
728 |
#設置符合權限
|
|
|
729 |
$result["passed"]="true";
|
|
|
730 |
|
|
|
731 |
#設置執行正常
|
|
|
732 |
$result["status"]="true";
|
|
|
733 |
|
|
|
734 |
#回傳結果
|
|
|
735 |
return $result;
|
|
|
736 |
|
|
|
737 |
}#if end
|
|
|
738 |
|
|
|
739 |
#反之代表沒有找到相符的資料,不符合權限.
|
|
|
740 |
else{
|
|
|
741 |
|
|
|
742 |
#設置符合權限
|
|
|
743 |
$result["passed"]="false";
|
|
|
744 |
|
|
|
745 |
#設置執行正常
|
|
|
746 |
$result["status"]="true";
|
|
|
747 |
|
|
|
748 |
#設置警告訊息
|
|
|
749 |
$result["warning"][]="使用者所屬的群組沒有權限使用該子系統";
|
|
|
750 |
|
|
|
751 |
#回傳結果
|
|
|
752 |
return $result;
|
|
|
753 |
|
|
|
754 |
}#else end
|
|
|
755 |
|
|
|
756 |
}#else end
|
|
|
757 |
|
|
|
758 |
#執行到這邊代表執行不正常
|
|
|
759 |
$result["status"]="false";
|
|
|
760 |
|
|
|
761 |
#設置錯誤訊息
|
|
|
762 |
$result["error"][]="不應該執行到的位置";
|
|
|
763 |
|
|
|
764 |
#回傳結果
|
|
|
765 |
return $result;
|
|
|
766 |
|
|
|
767 |
}#函式結束
|
|
|
768 |
|
|
|
769 |
/*
|
|
|
770 |
#函式說明:
|
|
|
771 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
772 |
#回傳的解果:
|
|
|
773 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
774 |
#$result["error"],錯誤訊息.
|
|
|
775 |
#$result["function"],檔前執行的函數名稱.
|
|
|
776 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
777 |
#$result["imgAddress"],包含src圖片的位置與名稱.
|
|
|
778 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
779 |
#必填參數:
|
|
|
780 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
781 |
$conf["imgAddressAndName"]="";
|
|
|
782 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
783 |
$conf["fileArgu"]=__FILE__;
|
|
|
784 |
#可省略參數:
|
|
|
785 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
786 |
#$conf["num"]="8";
|
|
|
787 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
788 |
#$conf["disableImg"]="false";
|
|
|
789 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
790 |
#$conf["imgToData"]="true";
|
|
|
791 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
792 |
#$conf["class"]="";
|
|
|
793 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
794 |
#$conf["content"]=array();
|
| 171 |
liveuser |
795 |
#參考資料:
|
|
|
796 |
#無.
|
| 1 |
liveuser |
797 |
#備註:
|
|
|
798 |
#無.
|
|
|
799 |
*/
|
|
|
800 |
public static function validationCode(&$conf){
|
|
|
801 |
|
|
|
802 |
#初始化要回傳的結果
|
|
|
803 |
$result=array();
|
|
|
804 |
|
|
|
805 |
#取得當前執行的函數
|
|
|
806 |
$result["function"]=__FUNCTION__;
|
|
|
807 |
|
|
|
808 |
#如果 $conf 不為陣列
|
|
|
809 |
if(gettype($conf)!="array"){
|
|
|
810 |
|
|
|
811 |
#設置執行失敗
|
|
|
812 |
$result["status"]="false";
|
|
|
813 |
|
|
|
814 |
#設置執行錯誤訊息
|
|
|
815 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
816 |
|
|
|
817 |
#如果傳入的參數為 null
|
|
|
818 |
if($conf==null){
|
|
|
819 |
|
|
|
820 |
#設置執行錯誤訊息
|
|
|
821 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
822 |
|
|
|
823 |
}#if end
|
|
|
824 |
|
|
|
825 |
#回傳結果
|
|
|
826 |
return $result;
|
|
|
827 |
|
|
|
828 |
}#if end
|
|
|
829 |
|
|
|
830 |
#檢查參數
|
|
|
831 |
#函式說明:
|
|
|
832 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
833 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
834 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
835 |
#$result["function"],當前執行的函式名稱.
|
|
|
836 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
837 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
838 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
839 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
840 |
#必填參數:
|
|
|
841 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
842 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
843 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
844 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddressAndName","fileArgu");
|
|
|
845 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
846 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
847 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
848 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
849 |
#可以省略的參數:
|
|
|
850 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
851 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
852 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
853 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","num","disableImg","imgToData","class","content");
|
|
|
854 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
855 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array");
|
|
|
856 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
857 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"8","false","true",null,array("1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","V","U","W","X","Y","Z"));
|
|
|
858 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
859 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
860 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
861 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
862 |
|
|
|
863 |
#如果檢查失敗
|
|
|
864 |
if($checkResult["status"]=="false"){
|
|
|
865 |
|
|
|
866 |
#設置錯誤狀態
|
|
|
867 |
$result["status"]="false";
|
|
|
868 |
|
|
|
869 |
#設置錯誤提示
|
|
|
870 |
$result["error"]=$checkResult;
|
|
|
871 |
|
|
|
872 |
return $result;
|
|
|
873 |
|
|
|
874 |
}#if end
|
|
|
875 |
|
|
|
876 |
#如果檢查不通過
|
|
|
877 |
if($checkResult["passed"]=="false"){
|
|
|
878 |
|
|
|
879 |
#設置錯誤狀態
|
|
|
880 |
$result["status"]="false";
|
|
|
881 |
|
|
|
882 |
#設置錯誤提示
|
|
|
883 |
$result["error"]=$checkResult;
|
|
|
884 |
|
|
|
885 |
return $result;
|
|
|
886 |
|
|
|
887 |
}#if end
|
|
|
888 |
|
|
|
889 |
#可以出現的亂數字碼
|
|
|
890 |
$target=$conf["content"];
|
|
|
891 |
|
|
|
892 |
#建立$randNumberWordUn的初始值
|
|
|
893 |
$randNumberWordUn="";
|
|
|
894 |
|
|
|
895 |
#跑$num次
|
|
|
896 |
for($i=0;$i<=($conf["num"]-1);$i++){
|
|
|
897 |
|
|
|
898 |
#則將該代數值轉換成對應的target陣列值。
|
|
|
899 |
$number[$i]=$target[rand(0,count($target)-1)];
|
|
|
900 |
|
|
|
901 |
#將轉換完的驗證碼合併
|
|
|
902 |
$randNumberWordUn=$randNumberWordUn.$number[$i];
|
|
|
903 |
|
|
|
904 |
}#for end
|
|
|
905 |
|
|
|
906 |
#將合併好的驗證碼到randNumberWord
|
|
|
907 |
$randNumberWord = $randNumberWordUn;
|
|
|
908 |
|
|
|
909 |
#如果有設定產出圖片
|
|
|
910 |
if($conf["disableImg"]=="false"){
|
|
|
911 |
|
|
|
912 |
#如果驗證碼數量爲$num則放置驗證碼的圖片寬度就等於
|
|
|
913 |
$backgroundImgWidth=$conf["num"]*10;
|
|
|
914 |
|
|
|
915 |
#函式說明:
|
|
|
916 |
#建立含有文字的png圖檔
|
|
|
917 |
#回傳的結果:
|
|
|
918 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
919 |
#$result["error"],錯誤訊息陣列
|
|
|
920 |
#$result["function"],當前執行的函數名稱
|
|
|
921 |
#$result["content"],圖片的位置與檔案名稱
|
|
|
922 |
#必填參數:
|
|
|
923 |
$conf["img::create"]["imgWidth"]=$backgroundImgWidth;#圖片的寬度(int)
|
|
|
924 |
$conf["img::create"]["imgHeight"]=20;#圖片的高度(int)
|
|
|
925 |
$conf["img::create"]["imgStoreAddAndName"]=$conf["imgAddressAndName"];#圖片要儲存到的地方以及其名稱
|
|
|
926 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
927 |
$conf["img::create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
928 |
#可省略參數:
|
|
|
929 |
#$conf["bgRedNum"]=0;#圖片的紅色底色數值0~255,預設爲0
|
|
|
930 |
#$conf["bgGreenNum"]=0;#圖片的綠色底色數值0~255,預設爲0
|
|
|
931 |
#$conf["bgBlueNum"]=0;#圖片的藍色底色數值0~255,預設爲0
|
|
|
932 |
$conf["img::create"]["strOnImg"]=$randNumberWord;#要出現在圖片上的文字,預設為""
|
|
|
933 |
#$conf["textRedNum"]=255;#文字顏色的紅色數值0~255,預設爲255
|
|
|
934 |
#$conf["textGreenNum"]=255;#文字顏色的綠色數值0~255,預設爲255
|
|
|
935 |
#$conf["textBlueNum"]=255;#文字顏色的藍色數值0~255,預設爲255
|
|
|
936 |
#$conf["drawLine"]=array("");#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
937 |
#在圖片上畫左下到右上的線
|
|
|
938 |
$conf["img::create"]["drawLine"][]="0,0,".$backgroundImgWidth.",".$conf["img::create"]["imgHeight"].",255,0,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
939 |
#在圖片上畫左上到右下的線
|
|
|
940 |
$conf["img::create"]["drawLine"][]="0,".$conf["img::create"]["imgHeight"].",".$backgroundImgWidth.",0,0,255,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
941 |
#在圖片上畫左中到右中的線
|
|
|
942 |
$conf["img::create"]["drawLine"][]="0,".($conf["img::create"]["imgHeight"]/2).",".$backgroundImgWidth.",".($conf["img::create"]["imgHeight"]/2).",0,0,255";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
943 |
#在圖片上畫中上到中下的線
|
|
|
944 |
$conf["img::create"]["drawLine"][]=($backgroundImgWidth/2).",".$conf["img::create"]["imgHeight"].",".($backgroundImgWidth/2).",0,50,50,50";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
945 |
$conf["img::create"]["replaceOriImg"]="true";#如果遇到相同名字會將之刪除,flase爲不要刪除,預設為"false".
|
|
|
946 |
#參考資料來源:
|
|
|
947 |
#imagecreate=>http://php.net/manual/en/function.imagecreate.php
|
|
|
948 |
#imagecolorallocate=>http://php.net/manual/en/function.imagecolorallocate.php
|
|
|
949 |
#imagestring=>http://php.net/manual/en/function.imagestring.php
|
|
|
950 |
#imageline=>http://php.net/manual/en/function.imageline.php
|
|
|
951 |
#imagepng=>http://php.net/manual/en/function.imagepng.php
|
|
|
952 |
#imagedestroy=>http://php.net/manual/en/function.imagedestroy.php
|
|
|
953 |
$imgAddress=img::create($conf["img::create"]);
|
|
|
954 |
unset($conf["img::create"]);
|
|
|
955 |
|
|
|
956 |
#如果建立圖片失敗
|
|
|
957 |
if($imgAddress["status"]=="false"){
|
|
|
958 |
|
|
|
959 |
#設置錯誤狀態
|
|
|
960 |
$result["status"]="false";
|
|
|
961 |
|
|
|
962 |
#設置錯誤提示
|
|
|
963 |
$result["error"]=$imgAddress;
|
|
|
964 |
|
|
|
965 |
return $result;
|
|
|
966 |
|
|
|
967 |
}#if end
|
|
|
968 |
|
|
|
969 |
#設置圖片的位置與名稱
|
|
|
970 |
$result["imgAddress"]=$imgAddress["content"];
|
|
|
971 |
|
|
|
972 |
#如果要把圖片轉存成base64
|
|
|
973 |
if($conf["imgToData"]=="true"){
|
|
|
974 |
|
|
|
975 |
#函數說明:
|
|
|
976 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
977 |
#回傳結果:
|
|
|
978 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
979 |
#$result["error"],錯誤訊息
|
|
|
980 |
#$result["content"]["imgWithoutImgTag"],img的src數值內容.
|
|
|
981 |
#$result["content"]["img"],圖片的連結資訊
|
|
|
982 |
#$result["function"],當前執行的函數名稱
|
|
|
983 |
#必填參數:
|
|
|
984 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
985 |
$conf["img::data"]["imgPosition"]=$result["imgAddress"];
|
|
|
986 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
987 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
988 |
#可省略參數:
|
|
|
989 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
990 |
#$conf["alt"]="";
|
|
|
991 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
992 |
|
|
|
993 |
#如果有設定 class
|
|
|
994 |
if(isset($conf["class"])){
|
|
|
995 |
|
|
|
996 |
#設置圖片的 class
|
|
|
997 |
$conf["img::data"]["class"]=$conf["class"];
|
|
|
998 |
|
|
|
999 |
}#if end
|
|
|
1000 |
|
|
|
1001 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
1002 |
#$conf["mimeType"]="image/*";
|
|
|
1003 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
1004 |
#$conf["compressType"]="base64";
|
|
|
1005 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
1006 |
$conf["img::data"]["delImg"]="true";
|
|
|
1007 |
#參考資料:
|
|
|
1008 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
1009 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
1010 |
$data=img::data($conf["img::data"]);
|
|
|
1011 |
unset($conf["img::data"]);
|
|
|
1012 |
|
|
|
1013 |
#如果轉存成base64失敗
|
|
|
1014 |
if($data["status"]=="false"){
|
|
|
1015 |
|
|
|
1016 |
#設置錯誤狀態
|
|
|
1017 |
$result["status"]="false";
|
|
|
1018 |
|
|
|
1019 |
#設置錯誤提示
|
|
|
1020 |
$result["error"]=$data;
|
|
|
1021 |
|
|
|
1022 |
return $result;
|
|
|
1023 |
|
|
|
1024 |
}#if end
|
|
|
1025 |
|
|
|
1026 |
#設置圖片src的數值
|
|
|
1027 |
$result["imgSrcVal"]=$data["content"]["imgWithoutImgTag"];
|
|
|
1028 |
|
|
|
1029 |
#更新圖片位置為base64
|
|
|
1030 |
$result["imgAddress"]=$data["content"]["img"];
|
|
|
1031 |
|
|
|
1032 |
}#if end
|
|
|
1033 |
|
|
|
1034 |
}#if end
|
|
|
1035 |
|
|
|
1036 |
#設置執行成功狀態
|
|
|
1037 |
$result["status"]="true";
|
|
|
1038 |
|
|
|
1039 |
#設置亂數文字結果
|
|
|
1040 |
$result["randNumberWord"]=$randNumberWord;
|
|
|
1041 |
|
|
|
1042 |
#回傳內容
|
|
|
1043 |
return $result;
|
|
|
1044 |
|
|
|
1045 |
}#函式結束
|
|
|
1046 |
|
|
|
1047 |
/*
|
|
|
1048 |
#函式說明:
|
|
|
1049 |
#產生亂數驗證碼或驗證亂數驗證碼與表單資料
|
|
|
1050 |
#回傳結果:
|
|
|
1051 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1052 |
#$result["error"],錯誤訊息.
|
|
|
1053 |
#$result["argu"],使用的參數.
|
|
|
1054 |
#$result["function"],當前執行的函數名稱.
|
|
|
1055 |
#$result["content"],語法.
|
|
|
1056 |
#必填參數:
|
|
|
1057 |
#$conf["fileArgu"]
|
|
|
1058 |
$conf["fileArgu"]=__FILE__;
|
|
|
1059 |
#可省略參數:
|
|
|
1060 |
#$conf["sendedName"],字串,傳送的post變數名稱,預設爲"formData".
|
|
|
1061 |
#$conf["sendedName"]="";
|
|
|
1062 |
#$conf["codeFormName"],字串,驗證碼表單的名稱,預設為"randomCode",對應的 session 變數名稱為 authenticate.verifyCodeAndFormData.$conf["codeFormName"]
|
|
|
1063 |
#$conf["codeFormName"]="randomCode";
|
|
|
1064 |
#$conf["names"],字串陣列,需要處理的表單必填變數.
|
|
|
1065 |
#$conf["names"]=array();
|
|
|
1066 |
#$conf["skipNames"],字串陣列,需要處理的表單可爲空變數.
|
|
|
1067 |
#$conf["skipNames"]=array();
|
| 171 |
liveuser |
1068 |
#參考資料:
|
|
|
1069 |
#無.
|
| 1 |
liveuser |
1070 |
#備註:
|
|
|
1071 |
#請跟javaScript類別的randomCode函式搭配.應用情境在會員登入、驗證與寄送Email表單.
|
|
|
1072 |
*/
|
|
|
1073 |
function verifyCodeAndFormData($conf){
|
|
|
1074 |
|
|
|
1075 |
#初始化要回傳的結果
|
|
|
1076 |
$result=array();
|
|
|
1077 |
|
|
|
1078 |
#取得當前執行的函數名稱
|
|
|
1079 |
$result["function"]=__FUNCTION__;
|
|
|
1080 |
|
|
|
1081 |
#如果沒有參數
|
|
|
1082 |
if(func_num_args()==0){
|
|
|
1083 |
|
|
|
1084 |
#設置執行失敗
|
|
|
1085 |
$result["status"]="false";
|
|
|
1086 |
|
|
|
1087 |
#設置執行錯誤訊息
|
|
|
1088 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1089 |
|
|
|
1090 |
#回傳結果
|
|
|
1091 |
return $result;
|
|
|
1092 |
|
|
|
1093 |
}#if en
|
|
|
1094 |
|
|
|
1095 |
#取得參數
|
|
|
1096 |
$result["argu"]=$conf;
|
|
|
1097 |
|
|
|
1098 |
#如果 $conf 不為陣列
|
|
|
1099 |
if(gettype($conf)!=="array"){
|
|
|
1100 |
|
|
|
1101 |
#設置執行失敗
|
|
|
1102 |
$result["status"]="false";
|
|
|
1103 |
|
|
|
1104 |
#設置執行錯誤訊息
|
|
|
1105 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1106 |
|
|
|
1107 |
#如果傳入的參數為 null
|
|
|
1108 |
if(is_null($conf)){
|
|
|
1109 |
|
|
|
1110 |
#設置執行錯誤訊息
|
|
|
1111 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1112 |
|
|
|
1113 |
}#if end
|
|
|
1114 |
|
|
|
1115 |
#回傳結果
|
|
|
1116 |
return $result;
|
|
|
1117 |
|
|
|
1118 |
}#if end
|
|
|
1119 |
|
|
|
1120 |
#函式說明:
|
|
|
1121 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1122 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1123 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1124 |
#$result["function"],當前執行的函式名稱.
|
|
|
1125 |
#$result["argu"],設置給予的參數.
|
|
|
1126 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1127 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1128 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1129 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1130 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1131 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1132 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1133 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1134 |
#必填寫的參數:
|
|
|
1135 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1136 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1137 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1138 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1139 |
#可以省略的參數:
|
|
|
1140 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1141 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
1142 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1143 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1144 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1145 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1146 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1147 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1148 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1149 |
#$conf["canBeEmpty"]=array();
|
|
|
1150 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1151 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sendedName","codeFormName","names","skipNames");
|
|
|
1152 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1153 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sendedName","codeFormName","names","skipNames");
|
|
|
1154 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1155 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
|
|
|
1156 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1157 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("formData","randomCode",null,null);
|
|
|
1158 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1159 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1160 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1161 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1162 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1163 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1164 |
#參考資料來源:
|
|
|
1165 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1166 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1167 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1168 |
|
|
|
1169 |
#如果出錯
|
|
|
1170 |
if($checkArguments["status"]==="false"){
|
|
|
1171 |
|
|
|
1172 |
#設置執行失敗
|
|
|
1173 |
$result["status"]="false";
|
|
|
1174 |
|
|
|
1175 |
#設置執行失敗
|
|
|
1176 |
$result["error"]=$checkArguments;
|
|
|
1177 |
|
|
|
1178 |
#回傳結果
|
|
|
1179 |
return $result;
|
|
|
1180 |
|
|
|
1181 |
}#if end
|
|
|
1182 |
|
|
|
1183 |
#如果出錯
|
|
|
1184 |
if($checkArguments["passed"]==="false"){
|
|
|
1185 |
|
|
|
1186 |
#設置執行失敗
|
|
|
1187 |
$result["status"]="false";
|
|
|
1188 |
|
|
|
1189 |
#設置執行失敗
|
|
|
1190 |
$result["error"]=$checkArguments;
|
|
|
1191 |
|
|
|
1192 |
#回傳結果
|
|
|
1193 |
return $result;
|
|
|
1194 |
|
|
|
1195 |
}#if end
|
|
|
1196 |
|
|
|
1197 |
#如果沒有設置 $conf["names"]
|
|
|
1198 |
if(!isset($conf["names"])){
|
|
|
1199 |
|
|
|
1200 |
#初始化
|
|
|
1201 |
$conf["names"]=array($conf["codeFormName"]);
|
|
|
1202 |
|
|
|
1203 |
}#if end
|
|
|
1204 |
|
|
|
1205 |
#反之
|
|
|
1206 |
else{
|
|
|
1207 |
|
|
|
1208 |
#加上驗證碼表單
|
|
|
1209 |
$conf["names"][]=$conf["codeFormName"];
|
|
|
1210 |
|
|
|
1211 |
}#else end
|
|
|
1212 |
|
|
|
1213 |
#如果沒有設置 $conf["skipNames"]
|
|
|
1214 |
if(!isset($conf["skipNames"])){
|
|
|
1215 |
|
|
|
1216 |
#初始化
|
|
|
1217 |
$conf["skipNames"]=array();
|
|
|
1218 |
|
|
|
1219 |
}#if end
|
|
|
1220 |
|
|
|
1221 |
#函式說明:
|
|
|
1222 |
#建立一個陣列,可以指派陣列的內容,然後回傳
|
|
|
1223 |
#回傳的結果:
|
|
|
1224 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1225 |
#$result["function"],當前執行的函數名稱.
|
|
|
1226 |
#$result["error"],錯誤訊息陣列.
|
|
|
1227 |
#$result["argu"],使用的參數.
|
|
|
1228 |
#$result["content"],爲陣列變數內容
|
|
|
1229 |
#必填參數:
|
|
|
1230 |
$conf["arrays::create"]["arrayContent"]=array("string");#陣列元素的內容,須爲陣列值。
|
|
|
1231 |
#可省略參數:
|
|
|
1232 |
$conf["arrays::create"]["arrayCounts"]=count($conf["names"])+count($conf["skipNames"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
|
|
|
1233 |
$conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
|
|
|
1234 |
$create=arrays::create($conf["arrays::create"]);
|
|
|
1235 |
unset($conf["arrays::create"]);
|
|
|
1236 |
|
|
|
1237 |
#如果失敗
|
|
|
1238 |
if($create["status"]==="false"){
|
|
|
1239 |
|
|
|
1240 |
#設置執行失敗
|
|
|
1241 |
$result["status"]="false";
|
|
|
1242 |
|
|
|
1243 |
#設置執行失敗
|
|
|
1244 |
$result["error"]=$create;
|
|
|
1245 |
|
|
|
1246 |
#回傳結果
|
|
|
1247 |
return $result;
|
|
|
1248 |
|
|
|
1249 |
}#if end
|
|
|
1250 |
|
|
|
1251 |
#函式說明:
|
|
|
1252 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
1253 |
#回傳的結果:
|
|
|
1254 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
1255 |
#$result["error"],錯誤訊息陣列.
|
|
|
1256 |
#$result["function"],當前執行的函數.
|
|
|
1257 |
#$result["content"],合併好的一維陣列.
|
|
|
1258 |
#必填的參數
|
|
|
1259 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
1260 |
$conf["arrays::mergeArray"]["inputArray"]=array($conf["names"],$conf["skipNames"]);
|
|
|
1261 |
#可省略的參數:
|
|
|
1262 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
1263 |
#$conf["allowRepeat"]="true";
|
|
|
1264 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
1265 |
unset($conf["arrays::mergeArray"]);
|
|
|
1266 |
|
|
|
1267 |
#如果失敗
|
|
|
1268 |
if($mergeArray["status"]==="false"){
|
|
|
1269 |
|
|
|
1270 |
#設置執行失敗
|
|
|
1271 |
$result["status"]="false";
|
|
|
1272 |
|
|
|
1273 |
#設置執行失敗
|
|
|
1274 |
$result["error"]=$mergeArray;
|
|
|
1275 |
|
|
|
1276 |
#回傳結果
|
|
|
1277 |
return $result;
|
|
|
1278 |
|
|
|
1279 |
}#if end
|
|
|
1280 |
|
|
|
1281 |
#如表單變數存在
|
|
|
1282 |
if(isset($_POST[$conf["sendedName"]])){
|
|
|
1283 |
|
|
|
1284 |
#解碼
|
|
|
1285 |
$urlEncodeStr=base64_decode($_POST[$conf["sendedName"]]);
|
|
|
1286 |
|
|
|
1287 |
#解碼
|
|
|
1288 |
$jsonEncodeStr=urldecode($urlEncodeStr);
|
|
|
1289 |
|
|
|
1290 |
#解碼
|
|
|
1291 |
$obj=json_decode($jsonEncodeStr);
|
|
|
1292 |
|
|
|
1293 |
#debug
|
|
|
1294 |
#echo $urlEncodeStr."<p>";
|
|
|
1295 |
#echo $jsonEncodeStr."<p>";
|
|
|
1296 |
#var_dump($obj);
|
|
|
1297 |
|
|
|
1298 |
#如果爲空物件
|
|
|
1299 |
if($jsonEncodeStr==="{}"){
|
|
|
1300 |
|
|
|
1301 |
#建立亂數驗證碼
|
|
|
1302 |
#函式說明:
|
|
|
1303 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
1304 |
#回傳的解果:
|
|
|
1305 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1306 |
#$result["error"],錯誤訊息.
|
|
|
1307 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1308 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
1309 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
1310 |
#$result["imgAddress"],圖片的位置與名稱.
|
|
|
1311 |
#必填的參數:
|
|
|
1312 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
1313 |
$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/authenticate.verifyCodeAndFormData.".$conf["codeFormName"];
|
|
|
1314 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1315 |
$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1316 |
#可省略參數:
|
|
|
1317 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
1318 |
#$conf["num"]="8";
|
|
|
1319 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
1320 |
#$conf["disableImg"]="false";
|
|
|
1321 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
1322 |
#$conf["imgToData"]="true";
|
|
|
1323 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
1324 |
#$conf["class"]="";
|
|
|
1325 |
$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
|
|
|
1326 |
unset($conf["authenticate::validationCode"]);
|
|
|
1327 |
|
|
|
1328 |
#如果建立亂碼圖片失敗
|
|
|
1329 |
if($validationCode["status"]==="false"){
|
|
|
1330 |
|
|
|
1331 |
#設置執行失敗
|
|
|
1332 |
$result["status"]="false";
|
|
|
1333 |
|
|
|
1334 |
#設置執行失敗
|
|
|
1335 |
$result["error"]=$validationCode;
|
|
|
1336 |
|
|
|
1337 |
#回傳結果
|
|
|
1338 |
return $result;
|
|
|
1339 |
|
|
|
1340 |
}#if end
|
|
|
1341 |
|
|
|
1342 |
#設置驗證碼到session變數
|
|
|
1343 |
$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]=$validationCode["randNumberWord"];
|
|
|
1344 |
|
|
|
1345 |
#取得驗證碼長度
|
|
|
1346 |
$json["content"]["randomCodeLength"]=strlen($_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]);
|
|
|
1347 |
|
|
|
1348 |
#設置圖片data
|
|
|
1349 |
$json["content"]["randomCodeSrc"]=$validationCode["imgSrcVal"];
|
|
|
1350 |
|
|
|
1351 |
#設置執行失敗
|
|
|
1352 |
$json["status"]="false";
|
|
|
1353 |
|
|
|
1354 |
#設置執行錯誤
|
|
|
1355 |
$json["error"]="no data";
|
|
|
1356 |
|
|
|
1357 |
#設置 json
|
|
|
1358 |
$result["content"]=json_encode($json);
|
|
|
1359 |
|
|
|
1360 |
#運行正常
|
|
|
1361 |
$result["status"]="true";
|
|
|
1362 |
|
|
|
1363 |
#回傳結果
|
|
|
1364 |
return $result;
|
|
|
1365 |
|
|
|
1366 |
}#if end
|
|
|
1367 |
|
|
|
1368 |
#反之有內容
|
|
|
1369 |
else{
|
|
|
1370 |
|
|
|
1371 |
#清空post變數
|
|
|
1372 |
$_POST=array();
|
|
|
1373 |
|
|
|
1374 |
#debug
|
|
|
1375 |
#echo $urlEncodeStr."<p>";
|
|
|
1376 |
#echo $jsonEncodeStr."<p>";
|
|
|
1377 |
#var_dump($obj);
|
|
|
1378 |
|
|
|
1379 |
#依據每個物件
|
|
|
1380 |
foreach($obj as $key=>$val){
|
|
|
1381 |
|
|
|
1382 |
#設置對應的 post 數值
|
|
|
1383 |
$_POST[$key]=$val;
|
|
|
1384 |
|
|
|
1385 |
}#foreach end
|
|
|
1386 |
|
|
|
1387 |
#debug
|
|
|
1388 |
#echo json_encode($_POST);
|
|
|
1389 |
|
|
|
1390 |
#如果驗證碼正確
|
|
|
1391 |
if($_POST["randomCode"]===$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]){
|
|
|
1392 |
|
|
|
1393 |
#設置執行正常
|
|
|
1394 |
$json["status"]="true";
|
|
|
1395 |
|
|
|
1396 |
#設置通過驗證
|
|
|
1397 |
$json["passed"]="true";
|
|
|
1398 |
|
|
|
1399 |
#設置訊息
|
|
|
1400 |
$json["msg"]="通過驗證";
|
|
|
1401 |
|
|
|
1402 |
#取得要檢查的變數名稱
|
|
|
1403 |
$mustBeFilledVariableName=$mergeArray["content"];
|
|
|
1404 |
|
|
|
1405 |
#取得要檢查的變數形態
|
|
|
1406 |
$mustBeFilledVariableType=$create["content"];
|
|
|
1407 |
|
|
|
1408 |
#檢查POST參數
|
|
|
1409 |
#函式說明:
|
|
|
1410 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1411 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1412 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1413 |
#$result["function"],當前執行的函式名稱.
|
|
|
1414 |
#$result["argu"],設置給予的參數.
|
|
|
1415 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1416 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1417 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1418 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1419 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1420 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1421 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1422 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1423 |
#必填寫的參數:
|
|
|
1424 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1425 |
$conf["variableCheck::checkArguments"]["varInput"]=&$_POST;
|
|
|
1426 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1427 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1428 |
#可以省略的參數:
|
|
|
1429 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1430 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=$mustBeFilledVariableName;
|
|
|
1431 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1432 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=$mustBeFilledVariableType;
|
|
|
1433 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1434 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
1435 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1436 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=$conf["names"];
|
|
|
1437 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1438 |
#$conf["canBeEmpty"]=array();
|
|
|
1439 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1440 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1441 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1442 |
#$conf["skipableVariableName"]=array();
|
|
|
1443 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1444 |
#$conf["skipableVariableType"]=array();
|
|
|
1445 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1446 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1447 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1448 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1449 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1450 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1451 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1452 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1453 |
#參考資料來源:
|
|
|
1454 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1455 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1456 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1457 |
|
|
|
1458 |
#如果檢查失敗
|
|
|
1459 |
if($checkArguments["status"]==="false"){
|
|
|
1460 |
|
|
|
1461 |
#設置執行不正常
|
|
|
1462 |
$jsons["status"]="false";
|
|
|
1463 |
|
|
|
1464 |
#設置檢查不通過
|
|
|
1465 |
$json["passed"]="false";
|
|
|
1466 |
|
|
|
1467 |
#設置執行失敗
|
|
|
1468 |
$json["error"]=$checkArguments;
|
|
|
1469 |
|
|
|
1470 |
#設置 json
|
|
|
1471 |
$result["content"]=json_encode($json);
|
|
|
1472 |
|
|
|
1473 |
#運行正常
|
|
|
1474 |
$result["status"]="true";
|
|
|
1475 |
|
|
|
1476 |
#回傳結果
|
|
|
1477 |
return $result;
|
|
|
1478 |
|
|
|
1479 |
}#if end
|
|
|
1480 |
|
|
|
1481 |
#如果檢查不通過
|
|
|
1482 |
if($checkArguments["passed"]==="false"){
|
|
|
1483 |
|
|
|
1484 |
#設置執行正常
|
|
|
1485 |
$json["status"]="true";
|
|
|
1486 |
|
|
|
1487 |
#設置檢查不通過
|
|
|
1488 |
$json["passed"]="false";
|
|
|
1489 |
|
|
|
1490 |
#設置執行失敗
|
|
|
1491 |
$json["error"]=$checkArguments;
|
|
|
1492 |
|
|
|
1493 |
#設置 json
|
|
|
1494 |
$result["content"]=json_encode($json);
|
|
|
1495 |
|
|
|
1496 |
#運行正常
|
|
|
1497 |
$result["status"]="true";
|
|
|
1498 |
|
|
|
1499 |
#回傳結果
|
|
|
1500 |
return $result;
|
|
|
1501 |
|
|
|
1502 |
}#if end
|
|
|
1503 |
|
|
|
1504 |
#設置執行正常
|
|
|
1505 |
$json["status"]="true";
|
|
|
1506 |
|
|
|
1507 |
#設置通過驗證
|
|
|
1508 |
$json["passed"]="true";
|
|
|
1509 |
|
|
|
1510 |
#設置抓到的 post 內容
|
|
|
1511 |
$json["post"]=$_POST;
|
|
|
1512 |
|
|
|
1513 |
#設置 json
|
|
|
1514 |
$result["content"]=json_encode($json);
|
|
|
1515 |
|
|
|
1516 |
#運行正常
|
|
|
1517 |
$result["status"]="true";
|
|
|
1518 |
|
|
|
1519 |
#回傳結果
|
|
|
1520 |
return $result;
|
|
|
1521 |
|
|
|
1522 |
}#if end
|
|
|
1523 |
|
|
|
1524 |
#反之
|
|
|
1525 |
else{
|
|
|
1526 |
|
|
|
1527 |
#設置執行正常
|
|
|
1528 |
$json["status"]="true";
|
|
|
1529 |
|
|
|
1530 |
#設置未通過驗證
|
|
|
1531 |
$json["passed"]="false";
|
|
|
1532 |
|
|
|
1533 |
#設置錯誤訊息
|
|
|
1534 |
$json["error"]="驗證碼錯誤";
|
|
|
1535 |
|
|
|
1536 |
#設置 json
|
|
|
1537 |
$result["content"]=json_encode($json);
|
|
|
1538 |
|
|
|
1539 |
#運行正常
|
|
|
1540 |
$result["status"]="true";
|
|
|
1541 |
|
|
|
1542 |
#回傳結果
|
|
|
1543 |
return $result;
|
|
|
1544 |
|
|
|
1545 |
}#else end
|
|
|
1546 |
|
|
|
1547 |
}#else end
|
|
|
1548 |
|
|
|
1549 |
#設置執行正常
|
|
|
1550 |
$json["status"]="false";
|
|
|
1551 |
|
|
|
1552 |
#設置通過驗證
|
|
|
1553 |
$json["passed"]="false";
|
|
|
1554 |
|
|
|
1555 |
#設置錯誤訊息
|
|
|
1556 |
$json["error"]="缺少POST變數";
|
|
|
1557 |
|
|
|
1558 |
#設置抓到的 post 內容
|
|
|
1559 |
$json["post"]=$_POST;
|
|
|
1560 |
|
|
|
1561 |
#設置 json
|
|
|
1562 |
$result["content"]=json_encode($json);
|
|
|
1563 |
|
|
|
1564 |
#運行不正常
|
|
|
1565 |
$result["status"]="false";
|
|
|
1566 |
|
|
|
1567 |
#設置錯誤訊息
|
|
|
1568 |
$result["error"][]="缺少POST變數";
|
|
|
1569 |
|
|
|
1570 |
#回傳結果
|
|
|
1571 |
return $result;
|
|
|
1572 |
|
|
|
1573 |
}#if end
|
|
|
1574 |
|
|
|
1575 |
}#function verifyCodeAndFormData end
|
|
|
1576 |
|
|
|
1577 |
/*
|
|
|
1578 |
#函式說明:
|
|
|
1579 |
#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
1580 |
#回傳結果:
|
|
|
1581 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1582 |
#$result["function"],當前執行的函數名稱.
|
|
|
1583 |
#$result["content"],加密後的結果.
|
|
|
1584 |
#$result["error"],錯誤訊息陣列.
|
|
|
1585 |
#$result["argu"],使用的參數.
|
|
|
1586 |
#必填參數:
|
| 660 |
liveuser |
1587 |
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
|
| 1 |
liveuser |
1588 |
$conf["enCodeStr"]="";
|
| 660 |
liveuser |
1589 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
|
| 1 |
liveuser |
1590 |
$conf["enCodeType"]="sha1";
|
|
|
1591 |
#可省略參數:
|
|
|
1592 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
1593 |
#$conf["sha1Raw"]="false";
|
|
|
1594 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
1595 |
#$conf["p_hash"]="";
|
|
|
1596 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
1597 |
#$conf["keyForAes256"]="";
|
|
|
1598 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
1599 |
#$conf["aes256Encode"]="";
|
| 660 |
liveuser |
1600 |
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
1601 |
#$conf["qbpwcfDecode"]="false";
|
| 171 |
liveuser |
1602 |
#參考資料:
|
| 660 |
liveuser |
1603 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
1604 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
1605 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
1606 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
1607 |
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
|
|
|
1608 |
#備註:
|
| 171 |
liveuser |
1609 |
#無.
|
| 1 |
liveuser |
1610 |
*/
|
|
|
1611 |
public static function enCodeStr(&$conf){
|
|
|
1612 |
|
|
|
1613 |
#初始化要回傳的結果
|
|
|
1614 |
$result=array();
|
|
|
1615 |
|
|
|
1616 |
#記錄當前執行的函數
|
|
|
1617 |
$result["function"]=__FUNCTION__;
|
|
|
1618 |
|
|
|
1619 |
#如果 $conf 不為陣列
|
|
|
1620 |
if(gettype($conf)!="array"){
|
|
|
1621 |
|
|
|
1622 |
#設置執行失敗
|
|
|
1623 |
$result["status"]="false";
|
|
|
1624 |
|
|
|
1625 |
#設置執行錯誤訊息
|
|
|
1626 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1627 |
|
|
|
1628 |
#如果傳入的參數為 null
|
|
|
1629 |
if($conf==null){
|
|
|
1630 |
|
|
|
1631 |
#設置執行錯誤訊息
|
|
|
1632 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1633 |
|
|
|
1634 |
}#if end
|
|
|
1635 |
|
|
|
1636 |
#回傳結果
|
|
|
1637 |
return $result;
|
|
|
1638 |
|
|
|
1639 |
}#if end
|
|
|
1640 |
|
|
|
1641 |
#計數使用的參數
|
|
|
1642 |
$result["argu"]=$conf;
|
|
|
1643 |
|
|
|
1644 |
#檢查參數
|
|
|
1645 |
#函式說明:
|
|
|
1646 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1647 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1648 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1649 |
#$result["function"],當前執行的函式名稱.
|
|
|
1650 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1651 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1652 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1653 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1654 |
#必填參數:
|
|
|
1655 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1656 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1657 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1658 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("enCodeStr","enCodeType");
|
|
|
1659 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 660 |
liveuser |
1660 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"string");
|
| 1 |
liveuser |
1661 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1662 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1663 |
#可以省略的參數:
|
|
|
1664 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1665 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1666 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 660 |
liveuser |
1667 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash","keyForAes256","aes256Encode","qbpwcfDecode");
|
| 1 |
liveuser |
1668 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 660 |
liveuser |
1669 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
|
| 1 |
liveuser |
1670 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 660 |
liveuser |
1671 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false");
|
| 1 |
liveuser |
1672 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1673 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1674 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1675 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1676 |
|
|
|
1677 |
#如果檢查參數失敗
|
|
|
1678 |
if($checkResult["status"]=="false"){
|
|
|
1679 |
|
|
|
1680 |
#設置執行失敗
|
|
|
1681 |
$result["status"]="false";
|
|
|
1682 |
|
|
|
1683 |
#設置執行錯誤
|
|
|
1684 |
$result["error"]=$checkResult;
|
|
|
1685 |
|
|
|
1686 |
#回傳結果
|
|
|
1687 |
return $result;
|
|
|
1688 |
|
|
|
1689 |
}#if end
|
|
|
1690 |
|
|
|
1691 |
#如果檢查參數不通過
|
|
|
1692 |
if($checkResult["passed"]=="false"){
|
|
|
1693 |
|
|
|
1694 |
#設置執行失敗
|
|
|
1695 |
$result["status"]="false";
|
|
|
1696 |
|
|
|
1697 |
#設置執行錯誤
|
|
|
1698 |
$result["error"]=$checkResult;
|
|
|
1699 |
|
|
|
1700 |
#回傳結果
|
|
|
1701 |
return $result;
|
|
|
1702 |
|
|
|
1703 |
}#if end
|
|
|
1704 |
|
|
|
1705 |
#判斷是哪一種加密方法
|
|
|
1706 |
switch($conf["enCodeType"]){
|
|
|
1707 |
|
|
|
1708 |
#如果是 "sha1"
|
|
|
1709 |
case "sha1":
|
|
|
1710 |
|
| 660 |
liveuser |
1711 |
#如果輸入不是字串
|
|
|
1712 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1713 |
|
|
|
1714 |
#設置執行失敗
|
|
|
1715 |
$result["status"]="false";
|
|
|
1716 |
|
|
|
1717 |
#設置執行錯誤
|
|
|
1718 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1719 |
|
|
|
1720 |
#回傳結果
|
|
|
1721 |
return $result;
|
|
|
1722 |
|
|
|
1723 |
}#if end
|
|
|
1724 |
|
| 1 |
liveuser |
1725 |
#如果要用2元碼輸出
|
|
|
1726 |
if($conf["sha1Raw"]=="true"){
|
|
|
1727 |
|
|
|
1728 |
#sha1加密
|
|
|
1729 |
$encodeStr=sha1($conf["enCodeStr"],TRUE);
|
|
|
1730 |
|
|
|
1731 |
#如果加密失敗
|
|
|
1732 |
if($encodeStr==false){
|
|
|
1733 |
|
|
|
1734 |
#設置執行失敗
|
|
|
1735 |
$result["status"]="false";
|
|
|
1736 |
|
|
|
1737 |
#設置執行錯誤
|
|
|
1738 |
$result["error"][]="加密失敗";
|
|
|
1739 |
|
|
|
1740 |
#回傳結果
|
|
|
1741 |
return $result;
|
|
|
1742 |
|
|
|
1743 |
}#if end
|
|
|
1744 |
|
|
|
1745 |
#反之加密成功
|
|
|
1746 |
else{
|
|
|
1747 |
|
|
|
1748 |
#取得加密後的字串
|
|
|
1749 |
$result["content"]=$encodeStr;
|
|
|
1750 |
|
|
|
1751 |
}#else end
|
|
|
1752 |
|
|
|
1753 |
}#if end
|
|
|
1754 |
|
|
|
1755 |
#反之用16進位數值輸出
|
|
|
1756 |
else{
|
|
|
1757 |
|
|
|
1758 |
#sha1加密
|
|
|
1759 |
$encodeStr=sha1($conf["enCodeStr"],FALSE);
|
|
|
1760 |
|
|
|
1761 |
#如果加密失敗
|
|
|
1762 |
if($encodeStr==false){
|
|
|
1763 |
|
|
|
1764 |
#設置執行失敗
|
|
|
1765 |
$result["status"]="false";
|
|
|
1766 |
|
|
|
1767 |
#設置執行錯誤
|
|
|
1768 |
$result["error"][]="加密失敗";
|
|
|
1769 |
|
|
|
1770 |
#回傳結果
|
|
|
1771 |
return $result;
|
|
|
1772 |
|
|
|
1773 |
}#if end
|
|
|
1774 |
|
|
|
1775 |
#反之加密成功
|
|
|
1776 |
else{
|
|
|
1777 |
|
|
|
1778 |
#取得加密後的字串
|
|
|
1779 |
$result["content"]=$encodeStr;
|
|
|
1780 |
|
|
|
1781 |
}#else end
|
|
|
1782 |
|
|
|
1783 |
}#else end
|
|
|
1784 |
|
|
|
1785 |
#跳出
|
|
|
1786 |
break;
|
|
|
1787 |
|
|
|
1788 |
#如果是 "md5"
|
|
|
1789 |
case "md5";
|
|
|
1790 |
|
| 660 |
liveuser |
1791 |
#如果輸入不是字串
|
|
|
1792 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1793 |
|
|
|
1794 |
#設置執行失敗
|
|
|
1795 |
$result["status"]="false";
|
|
|
1796 |
|
|
|
1797 |
#設置執行錯誤
|
|
|
1798 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1799 |
|
|
|
1800 |
#回傳結果
|
|
|
1801 |
return $result;
|
|
|
1802 |
|
|
|
1803 |
}#if end
|
|
|
1804 |
|
| 1 |
liveuser |
1805 |
#md5加密
|
|
|
1806 |
$encodeStr=md5($conf["enCodeStr"]);
|
|
|
1807 |
|
|
|
1808 |
#如果加密失敗
|
|
|
1809 |
if($encodeStr==false){
|
|
|
1810 |
|
|
|
1811 |
#設置執行失敗
|
|
|
1812 |
$result["status"]="false";
|
|
|
1813 |
|
|
|
1814 |
#設置執行錯誤
|
|
|
1815 |
$result["error"][]="加密失敗";
|
|
|
1816 |
|
|
|
1817 |
#回傳結果
|
|
|
1818 |
return $result;
|
|
|
1819 |
|
|
|
1820 |
}#if end
|
|
|
1821 |
|
|
|
1822 |
#反之加密成功
|
|
|
1823 |
else{
|
|
|
1824 |
|
|
|
1825 |
#取得加密後的字串
|
|
|
1826 |
$result["content"]=$encodeStr;
|
|
|
1827 |
|
|
|
1828 |
}#else end
|
|
|
1829 |
|
|
|
1830 |
#跳出
|
|
|
1831 |
break;
|
|
|
1832 |
|
|
|
1833 |
#如果是"p_hash"
|
|
|
1834 |
case "p_hash":
|
|
|
1835 |
|
| 660 |
liveuser |
1836 |
#如果輸入不是字串
|
|
|
1837 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1838 |
|
|
|
1839 |
#設置執行失敗
|
|
|
1840 |
$result["status"]="false";
|
|
|
1841 |
|
|
|
1842 |
#設置執行錯誤
|
|
|
1843 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1844 |
|
|
|
1845 |
#回傳結果
|
|
|
1846 |
return $result;
|
|
|
1847 |
|
|
|
1848 |
}#if end
|
|
|
1849 |
|
| 1 |
liveuser |
1850 |
#如果 $conf["p_hash"] 存在
|
|
|
1851 |
if(isset($conf["p_hash"])){
|
|
|
1852 |
|
|
|
1853 |
#檢驗 $conf["enCodeStr"] 是否與 $conf["p_hash"] 相符
|
|
|
1854 |
if(password_verify($conf["enCodeStr"],$conf["p_hash"])){
|
|
|
1855 |
|
|
|
1856 |
#設置執行正常
|
|
|
1857 |
$result["status"]="true";
|
|
|
1858 |
|
|
|
1859 |
#回傳結果
|
|
|
1860 |
return $result;
|
|
|
1861 |
|
| 660 |
liveuser |
1862 |
}#if end
|
|
|
1863 |
|
|
|
1864 |
#反之
|
| 1 |
liveuser |
1865 |
else{
|
|
|
1866 |
|
|
|
1867 |
#設置執行失敗
|
|
|
1868 |
$result["status"]="false";
|
|
|
1869 |
|
|
|
1870 |
#設置執行錯誤
|
|
|
1871 |
$result["error"][]="密碼不正確";
|
|
|
1872 |
|
|
|
1873 |
#回傳結果
|
|
|
1874 |
return $result;
|
|
|
1875 |
|
| 660 |
liveuser |
1876 |
}#else end
|
| 1 |
liveuser |
1877 |
|
|
|
1878 |
}#if end
|
|
|
1879 |
|
|
|
1880 |
#加密密碼
|
|
|
1881 |
$encodeStr=password_hash($conf["enCodeStr"],PASSWORD_DEFAULT);
|
|
|
1882 |
|
|
|
1883 |
#如果加密失敗
|
|
|
1884 |
if($encodeStr==false){
|
|
|
1885 |
|
|
|
1886 |
#設置執行失敗
|
|
|
1887 |
$result["status"]="false";
|
|
|
1888 |
|
|
|
1889 |
#設置執行錯誤
|
|
|
1890 |
$result["error"][]="加密失敗";
|
|
|
1891 |
|
|
|
1892 |
#回傳結果
|
|
|
1893 |
return $result;
|
|
|
1894 |
|
|
|
1895 |
}#if end
|
|
|
1896 |
|
|
|
1897 |
#反之加密成功
|
|
|
1898 |
else{
|
|
|
1899 |
|
|
|
1900 |
#取得加密後的字串
|
|
|
1901 |
$result["content"]=$encodeStr;
|
|
|
1902 |
|
|
|
1903 |
}#else end
|
|
|
1904 |
|
|
|
1905 |
break;
|
|
|
1906 |
|
|
|
1907 |
#如果是 AES 256 bit 加密
|
|
|
1908 |
#參考資料:
|
|
|
1909 |
#https://www.ucamc.com/e-learning/php/388-php%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8aes-openssl%E5%8A%A0%E5%AF%86%E4%BB%A3%E7%A2%BC%E3%80%81encrypt%E3%80%81decrypt
|
|
|
1910 |
case "aes256":
|
|
|
1911 |
|
| 660 |
liveuser |
1912 |
#如果輸入不是字串
|
|
|
1913 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1914 |
|
|
|
1915 |
#設置執行失敗
|
|
|
1916 |
$result["status"]="false";
|
|
|
1917 |
|
|
|
1918 |
#設置執行錯誤
|
|
|
1919 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1920 |
|
|
|
1921 |
#回傳結果
|
|
|
1922 |
return $result;
|
|
|
1923 |
|
|
|
1924 |
}#if end
|
|
|
1925 |
|
| 1 |
liveuser |
1926 |
#如果參數有缺
|
| 660 |
liveuser |
1927 |
if( !isset($conf["keyForAes256"]) || !isset($conf["aes256Encode"]) ){
|
| 1 |
liveuser |
1928 |
|
|
|
1929 |
#設置執行失敗
|
|
|
1930 |
$result["status"]="false";
|
|
|
1931 |
|
|
|
1932 |
#設置執行錯誤
|
|
|
1933 |
$result["error"][]="aes256 演算法需要 keyForAes256 與 aes256Encode 參數";
|
|
|
1934 |
|
|
|
1935 |
#回傳結果
|
|
|
1936 |
return $result;
|
|
|
1937 |
|
| 660 |
liveuser |
1938 |
}#if end
|
| 1 |
liveuser |
1939 |
|
|
|
1940 |
#如果是要加密
|
| 660 |
liveuser |
1941 |
if($conf["aes256Encode"]==="true"){
|
|
|
1942 |
|
| 1 |
liveuser |
1943 |
#取得iv
|
|
|
1944 |
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
|
|
1945 |
|
|
|
1946 |
#加密內容
|
|
|
1947 |
$encrypted = openssl_encrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
|
|
|
1948 |
|
|
|
1949 |
#使用base64加密的內容
|
|
|
1950 |
$result["content"]=base64_encode($encrypted . '::' . $iv);
|
|
|
1951 |
|
|
|
1952 |
#數值執行正常
|
|
|
1953 |
$result["status"]="true";
|
|
|
1954 |
|
|
|
1955 |
#回傳結果
|
|
|
1956 |
return $result;
|
|
|
1957 |
|
| 660 |
liveuser |
1958 |
}#if end
|
| 1 |
liveuser |
1959 |
|
|
|
1960 |
#反之是要解密
|
| 660 |
liveuser |
1961 |
else{
|
|
|
1962 |
|
| 1 |
liveuser |
1963 |
#取得 base64_decoed 的本文與 iv
|
|
|
1964 |
list($conf["enCodeStr"], $iv) = explode('::', base64_decode($conf["enCodeStr"]), 2);
|
|
|
1965 |
|
|
|
1966 |
#取得 解密好的內容
|
|
|
1967 |
$result["content"]=openssl_decrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
|
|
|
1968 |
|
|
|
1969 |
#數值執行正常
|
|
|
1970 |
$result["status"]="true";
|
|
|
1971 |
|
|
|
1972 |
#回傳結果
|
|
|
1973 |
return $result;
|
|
|
1974 |
|
| 660 |
liveuser |
1975 |
}#else end
|
| 1 |
liveuser |
1976 |
|
| 660 |
liveuser |
1977 |
#跳出迴圈
|
| 1 |
liveuser |
1978 |
break;
|
| 660 |
liveuser |
1979 |
|
|
|
1980 |
#如果是 "qbpwcf"
|
|
|
1981 |
case "qbpwcf":
|
|
|
1982 |
|
|
|
1983 |
#如果是要加密
|
|
|
1984 |
if($conf["qbpwcfDecode"]==="false"){
|
|
|
1985 |
|
|
|
1986 |
#to json string
|
|
|
1987 |
$jsonData=json_encode($conf["enCodeStr"]);
|
| 1 |
liveuser |
1988 |
|
| 660 |
liveuser |
1989 |
#如果出錯
|
|
|
1990 |
if($jsonData===false){
|
|
|
1991 |
|
|
|
1992 |
#設置執行失敗
|
|
|
1993 |
$result["status"]="false";
|
|
|
1994 |
|
|
|
1995 |
#設置執行錯誤
|
|
|
1996 |
$result["error"][]="encode 「".$conf["enCodeStr"]."」 失敗";
|
|
|
1997 |
|
|
|
1998 |
#回傳結果
|
|
|
1999 |
return $result;
|
|
|
2000 |
|
|
|
2001 |
}#if end
|
|
|
2002 |
|
|
|
2003 |
#設置加密好的內容
|
|
|
2004 |
$result["content"]=base64_encode(urlencode($jsonData));
|
|
|
2005 |
|
|
|
2006 |
}#if end
|
|
|
2007 |
|
|
|
2008 |
#反之是要解密
|
|
|
2009 |
else{
|
|
|
2010 |
|
|
|
2011 |
#base64_decode then urldecode data
|
|
|
2012 |
$urlDecodeData=urldecode(base64_decode($conf["enCodeStr"]));
|
|
|
2013 |
|
|
|
2014 |
#json_decode data
|
|
|
2015 |
$json_decode_data=json_decode($urlDecodeData);
|
|
|
2016 |
|
|
|
2017 |
#如果異常
|
|
|
2018 |
if($urlDecodeData!==null && $json_decode_data===null){
|
|
|
2019 |
|
|
|
2020 |
#設置執行失敗
|
|
|
2021 |
$result["status"]="false";
|
|
|
2022 |
|
|
|
2023 |
#設置執行錯誤
|
|
|
2024 |
$result["error"][]="decode 「".$conf["enCodeStr"]."」 失敗";
|
|
|
2025 |
|
|
|
2026 |
#回傳結果
|
|
|
2027 |
return $result;
|
|
|
2028 |
|
|
|
2029 |
}#if end
|
|
|
2030 |
|
|
|
2031 |
#設置解密好的內容
|
|
|
2032 |
$result["content"]=$json_decode_data;
|
|
|
2033 |
|
|
|
2034 |
}#else end
|
|
|
2035 |
|
|
|
2036 |
#跳出迴圈
|
|
|
2037 |
break;
|
|
|
2038 |
|
| 1 |
liveuser |
2039 |
#如果是其他內容
|
|
|
2040 |
default:
|
|
|
2041 |
|
|
|
2042 |
#設置執行失敗
|
|
|
2043 |
$result["status"]="false";
|
|
|
2044 |
|
|
|
2045 |
#設置執行錯誤
|
|
|
2046 |
$result["error"][]="不支援的加密方法「".$conf["enCodeType"]."」";
|
|
|
2047 |
|
|
|
2048 |
#回傳結果
|
|
|
2049 |
return $result;
|
|
|
2050 |
|
|
|
2051 |
}#switch end
|
|
|
2052 |
|
|
|
2053 |
#執行到這邊代表執行正常
|
|
|
2054 |
$result["status"]="true";
|
|
|
2055 |
|
|
|
2056 |
#回傳結果
|
|
|
2057 |
return $result;
|
|
|
2058 |
|
|
|
2059 |
}#function enCodeStr end
|
|
|
2060 |
|
|
|
2061 |
/*
|
|
|
2062 |
#函式說明:
|
|
|
2063 |
#將字串變成2元碼或2元碼變成字串.
|
|
|
2064 |
#回傳結果:
|
|
|
2065 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2066 |
#$result["function"],當前執行的函數名稱.
|
|
|
2067 |
#$result["content"],加密後的結果.
|
|
|
2068 |
#$result["error"],錯誤訊息陣列.
|
|
|
2069 |
#必填參數:
|
|
|
2070 |
#$conf["input"],"字串",要hex或unhex的字串
|
|
|
2071 |
$conf["input"]="";
|
|
|
2072 |
#$conf["action"],"字串",要toBin或toStr.
|
|
|
2073 |
$conf["action"]="";
|
|
|
2074 |
#可省略參數:
|
|
|
2075 |
#無.
|
| 171 |
liveuser |
2076 |
#參考資料:
|
|
|
2077 |
#hex2bin=>http://php.net/manual/en/function.hex2bin.php #bin2hex=>http://php.net/manual/en/function.binhex.php #pack=>http://php.net/manual/en/function.pack.php 轉換的方法似乎有問題. bin2hex可以將10進位數字字串轉換成2進位字串.
|
|
|
2078 |
#備註:
|
|
|
2079 |
#無.
|
| 1 |
liveuser |
2080 |
*/
|
|
|
2081 |
public static function str2bin(&$conf){
|
|
|
2082 |
|
|
|
2083 |
#初始化要回傳的結果
|
|
|
2084 |
$result=array();
|
|
|
2085 |
|
|
|
2086 |
#記錄當前執行的函數
|
|
|
2087 |
$result["function"]=__FUNCTION__;
|
|
|
2088 |
|
|
|
2089 |
#如果沒有參數
|
|
|
2090 |
if(func_num_args()==0){
|
|
|
2091 |
|
|
|
2092 |
#設置執行失敗
|
|
|
2093 |
$result["status"]="false";
|
|
|
2094 |
|
|
|
2095 |
#設置執行錯誤訊息
|
|
|
2096 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2097 |
|
|
|
2098 |
#回傳結果
|
|
|
2099 |
return $result;
|
|
|
2100 |
|
|
|
2101 |
}#if end
|
|
|
2102 |
|
|
|
2103 |
#如果 $conf 不為陣列
|
|
|
2104 |
if(gettype($conf)!="array"){
|
|
|
2105 |
|
|
|
2106 |
#設置執行失敗
|
|
|
2107 |
$result["status"]="false";
|
|
|
2108 |
|
|
|
2109 |
#設置執行錯誤訊息
|
|
|
2110 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2111 |
|
|
|
2112 |
#如果傳入的參數為 null
|
|
|
2113 |
if($conf==null){
|
|
|
2114 |
|
|
|
2115 |
#設置執行錯誤訊息
|
|
|
2116 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2117 |
|
|
|
2118 |
}#if end
|
|
|
2119 |
|
|
|
2120 |
#回傳結果
|
|
|
2121 |
return $result;
|
|
|
2122 |
|
|
|
2123 |
}#if end
|
|
|
2124 |
|
|
|
2125 |
#檢查參數
|
|
|
2126 |
#函式說明:
|
|
|
2127 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2128 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2129 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2130 |
#$result["function"],當前執行的函式名稱.
|
|
|
2131 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2132 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2133 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2134 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2135 |
#必填參數:
|
|
|
2136 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2137 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2138 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2139 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","action");
|
|
|
2140 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2141 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2142 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2143 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2144 |
#可以省略的參數:
|
|
|
2145 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2146 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2147 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2148 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash");
|
|
|
2149 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2150 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
2151 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2152 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
|
|
|
2153 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2154 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2155 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2156 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2157 |
|
|
|
2158 |
#如果檢查參數失敗
|
|
|
2159 |
if($checkResult["status"]=="false"){
|
|
|
2160 |
|
|
|
2161 |
#設置執行失敗
|
|
|
2162 |
$result["status"]="false";
|
|
|
2163 |
|
|
|
2164 |
#設置執行錯誤
|
|
|
2165 |
$result["error"]=$checkResult;
|
|
|
2166 |
|
|
|
2167 |
#回傳結果
|
|
|
2168 |
return $result;
|
|
|
2169 |
|
|
|
2170 |
}#if end
|
|
|
2171 |
|
|
|
2172 |
#如果要hex
|
|
|
2173 |
if($conf["action"]=="toBin"){
|
|
|
2174 |
|
|
|
2175 |
#將字串轉換成2進位
|
|
|
2176 |
$result["content"]=pack('H*', base_convert($conf["input"], 2, 16));
|
|
|
2177 |
|
|
|
2178 |
}#if end
|
|
|
2179 |
|
|
|
2180 |
#反之如果要unhex
|
|
|
2181 |
else if($conf["action"]=="toStr"){
|
|
|
2182 |
|
|
|
2183 |
#將2進位轉為字串
|
|
|
2184 |
$result["content"]=unpack('H*',$conf["input"]);
|
|
|
2185 |
|
|
|
2186 |
#針對每個字
|
|
|
2187 |
foreach($result["content"] as $key=>$bin){
|
|
|
2188 |
|
|
|
2189 |
#轉換成字串
|
|
|
2190 |
$result["content"][$key]=base_convert($result["content"][1], 16, 2);
|
|
|
2191 |
|
|
|
2192 |
}#foreach end
|
|
|
2193 |
|
|
|
2194 |
}#if end
|
|
|
2195 |
|
|
|
2196 |
#設置執行正常
|
|
|
2197 |
$result["status"]="true";
|
|
|
2198 |
|
|
|
2199 |
#回傳結果
|
|
|
2200 |
return $result;
|
|
|
2201 |
|
|
|
2202 |
}#function hex2bin end
|
|
|
2203 |
|
|
|
2204 |
/*
|
|
|
2205 |
#函式說明:
|
|
|
2206 |
#驗證Linux使用者的密碼是否正確.
|
|
|
2207 |
#回傳結果:
|
|
|
2208 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2209 |
#$result["function"],當前執行的函數名稱.
|
|
|
2210 |
#$result["error"],錯誤訊息陣列.
|
|
|
2211 |
#$result["warninig"],警告訊息陣列.
|
|
|
2212 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
2213 |
#必填參數:
|
|
|
2214 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
2215 |
$conf["username"]="";
|
|
|
2216 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
2217 |
$conf["password"]="";
|
|
|
2218 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2219 |
$conf["fileArgu"]=__FILE__;
|
|
|
2220 |
#可省略參數:
|
|
|
2221 |
#無.
|
| 171 |
liveuser |
2222 |
#參考資料:
|
|
|
2223 |
#無.
|
| 1 |
liveuser |
2224 |
#備註:
|
|
|
2225 |
#僅能在命令列環境下運行.
|
|
|
2226 |
*/
|
|
|
2227 |
public static function validUser(&$conf){
|
|
|
2228 |
|
|
|
2229 |
#初始化要回傳的結果
|
|
|
2230 |
$result=array();
|
|
|
2231 |
|
|
|
2232 |
#取得當前執行的函數名稱
|
|
|
2233 |
$result["function"]=__FUNCTION__;
|
|
|
2234 |
|
|
|
2235 |
#初始化警告訊息
|
|
|
2236 |
$result["warning"]=array();
|
|
|
2237 |
|
|
|
2238 |
#函式說明:
|
|
|
2239 |
#判斷當前環境為web還是cmd
|
|
|
2240 |
#回傳結果:
|
|
|
2241 |
#$result,"web"或"cmd"
|
|
|
2242 |
if(csInformation::getEnv()=="web"){
|
|
|
2243 |
|
|
|
2244 |
#設置執行失敗
|
|
|
2245 |
$result["status"]="false";
|
|
|
2246 |
|
|
|
2247 |
#設置執行錯誤訊息
|
|
|
2248 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
2249 |
|
|
|
2250 |
#回傳結果
|
|
|
2251 |
return $result;
|
|
|
2252 |
|
|
|
2253 |
}#if end
|
|
|
2254 |
|
|
|
2255 |
#如果沒有參數
|
|
|
2256 |
if(func_num_args()==0){
|
|
|
2257 |
|
|
|
2258 |
#設置執行失敗
|
|
|
2259 |
$result["status"]="false";
|
|
|
2260 |
|
|
|
2261 |
#設置執行錯誤訊息
|
|
|
2262 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2263 |
|
|
|
2264 |
#回傳結果
|
|
|
2265 |
return $result;
|
|
|
2266 |
|
|
|
2267 |
}#if end
|
|
|
2268 |
|
|
|
2269 |
#取得參數
|
|
|
2270 |
$result["argu"]=$conf;
|
|
|
2271 |
|
|
|
2272 |
#如果 $conf 不為陣列
|
|
|
2273 |
if(gettype($conf)!="array"){
|
|
|
2274 |
|
|
|
2275 |
#設置執行失敗
|
|
|
2276 |
$result["status"]="false";
|
|
|
2277 |
|
|
|
2278 |
#設置執行錯誤訊息
|
|
|
2279 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2280 |
|
|
|
2281 |
#如果傳入的參數為 null
|
|
|
2282 |
if($conf==null){
|
|
|
2283 |
|
|
|
2284 |
#設置執行錯誤訊息
|
|
|
2285 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2286 |
|
|
|
2287 |
}#if end
|
|
|
2288 |
|
|
|
2289 |
#回傳結果
|
|
|
2290 |
return $result;
|
|
|
2291 |
|
|
|
2292 |
}#if end
|
|
|
2293 |
|
|
|
2294 |
#檢查參數
|
|
|
2295 |
#函式說明:
|
|
|
2296 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2297 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2298 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2299 |
#$result["function"],當前執行的函式名稱.
|
|
|
2300 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2301 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2302 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2303 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2304 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2305 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2306 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2307 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2308 |
#必填參數:
|
|
|
2309 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2310 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2311 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2312 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","fileArgu");
|
|
|
2313 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2314 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2315 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2316 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2317 |
#可以省略的參數:
|
|
|
2318 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2319 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2320 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列
|
|
|
2321 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");
|
|
|
2322 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
|
|
|
2323 |
$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
|
|
|
2324 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
2325 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2326 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2327 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","conf","commentsArray","forceRewrite");
|
|
|
2328 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2329 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string");
|
|
|
2330 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2331 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"),"false");
|
|
|
2332 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2333 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
2334 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
2335 |
#參考資料來源:
|
|
|
2336 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2337 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2338 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2339 |
|
|
|
2340 |
#如果檢查參數失敗
|
|
|
2341 |
if($checkArguments["status"]=="false"){
|
|
|
2342 |
|
|
|
2343 |
#設置執行不正常
|
|
|
2344 |
$result["status"]="false";
|
|
|
2345 |
|
|
|
2346 |
#設置執行錯誤
|
|
|
2347 |
$result["error"]=$checkArguments;
|
|
|
2348 |
|
|
|
2349 |
#回傳結果
|
|
|
2350 |
return $result;
|
|
|
2351 |
|
|
|
2352 |
}#if end
|
|
|
2353 |
|
|
|
2354 |
#如果檢查參數不通過
|
|
|
2355 |
if($checkArguments["passed"]=="false"){
|
|
|
2356 |
|
|
|
2357 |
#設置執行不正常
|
|
|
2358 |
$result["status"]="false";
|
|
|
2359 |
|
|
|
2360 |
#設置執行錯誤
|
|
|
2361 |
$result["error"]=$checkArguments;
|
|
|
2362 |
|
|
|
2363 |
#回傳結果
|
|
|
2364 |
return $result;
|
|
|
2365 |
|
|
|
2366 |
}#if end
|
|
|
2367 |
|
|
|
2368 |
#檢查使用者是否存在
|
|
|
2369 |
#函式說明:
|
|
|
2370 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2371 |
#回傳的結果:
|
|
|
2372 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2373 |
#$result["error"],錯誤訊息陣列.
|
|
|
2374 |
#$result["function"],當前執行的函數名稱.
|
|
|
2375 |
#$result["cmd"],執行的指令內容.
|
|
|
2376 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
2377 |
#必填的參數
|
|
|
2378 |
#$conf["command"],字串,要執行的指令與.
|
| 454 |
liveuser |
2379 |
$conf["external::callShell"]["command"]="id";
|
| 1 |
liveuser |
2380 |
#可省略參數:
|
|
|
2381 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 454 |
liveuser |
2382 |
$conf["external::callShell"]["argu"]=array($conf["username"]);
|
| 1 |
liveuser |
2383 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2384 |
#$conf["enablePrintDescription"]="true";
|
|
|
2385 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
2386 |
#$conf["printDescription"]="";
|
|
|
2387 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
2388 |
#$conf["escapeshellarg"]="false";
|
|
|
2389 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
|
|
|
2390 |
#$conf["external::callShell"]["username"]="";
|
|
|
2391 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
|
|
|
2392 |
#$conf["external::callShell"]["password"]="";
|
|
|
2393 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
2394 |
$conf["external::callShell"]["useScript"]="true";
|
|
|
2395 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
2396 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2397 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
2398 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2399 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2400 |
#備註:
|
|
|
2401 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
|
|
|
2402 |
#參考資料:
|
|
|
2403 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2404 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2405 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2406 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2407 |
unset($conf["external::callShell"]);
|
|
|
2408 |
|
|
|
2409 |
#如果執行shell失敗
|
|
|
2410 |
if($callShell["status"]=="false"){
|
|
|
2411 |
|
|
|
2412 |
#設置執行不正常
|
|
|
2413 |
$result["status"]="false";
|
|
|
2414 |
|
|
|
2415 |
#設置執行錯誤
|
|
|
2416 |
$result["error"]=$callShell;
|
|
|
2417 |
|
|
|
2418 |
#回傳結果
|
|
|
2419 |
return $result;
|
|
|
2420 |
|
|
|
2421 |
}#if end
|
|
|
2422 |
|
|
|
2423 |
#如果使用者 $conf["username"] 不存在
|
|
|
2424 |
if($callShell["output"][0]=="id: ".$conf["username"].": no such user"){
|
|
|
2425 |
|
|
|
2426 |
#設置執行不正常
|
|
|
2427 |
$result["status"]="true";
|
|
|
2428 |
|
|
|
2429 |
#設置使用者驗證失敗
|
|
|
2430 |
$result["valid"]="false";
|
|
|
2431 |
|
|
|
2432 |
#設置使用者不存在的警告
|
|
|
2433 |
$result["warninig"][]="使用者 \"".$conf["username"]."\" 不存在!";
|
|
|
2434 |
|
|
|
2435 |
#回傳結果
|
|
|
2436 |
return $result;
|
|
|
2437 |
|
|
|
2438 |
}#if end
|
|
|
2439 |
|
|
|
2440 |
#可以用 echo 'password' | su username -c 'echo valid' 來檢查使用者密碼是否正確
|
|
|
2441 |
#檢查使用者是否存在
|
|
|
2442 |
#函式說明:
|
|
|
2443 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2444 |
#回傳的結果:
|
|
|
2445 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2446 |
#$result["error"],錯誤訊息陣列.
|
|
|
2447 |
#$result["function"],當前執行的函數名稱.
|
|
|
2448 |
#$result["cmd"],執行的指令內容.
|
|
|
2449 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
2450 |
#必填的參數
|
|
|
2451 |
#$conf["command"],字串,要執行的指令與.
|
| 454 |
liveuser |
2452 |
$conf["external::callShell"]["command"]="echo";
|
| 1 |
liveuser |
2453 |
#可省略參數:
|
|
|
2454 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 454 |
liveuser |
2455 |
$conf["external::callShell"]["argu"]=array($conf["password"],"|","su",$conf["username"],"-c","echo valid");
|
| 1 |
liveuser |
2456 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2457 |
#$conf["enablePrintDescription"]="true";
|
|
|
2458 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
2459 |
#$conf["printDescription"]="";
|
|
|
2460 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
2461 |
#$conf["escapeshellarg"]="false";
|
|
|
2462 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
|
|
|
2463 |
#$conf["external::callShell"]["username"]="";
|
|
|
2464 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
|
|
|
2465 |
#$conf["external::callShell"]["password"]="";
|
|
|
2466 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
2467 |
$conf["external::callShell"]["useScript"]="true";
|
|
|
2468 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
2469 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2470 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
2471 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2472 |
#備註:
|
|
|
2473 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
|
|
|
2474 |
#參考資料:
|
|
|
2475 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2476 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2477 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2478 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2479 |
unset($conf["external::callShell"]);
|
|
|
2480 |
|
|
|
2481 |
#如果執行shell失敗
|
|
|
2482 |
if($callShell["status"]=="false"){
|
|
|
2483 |
|
|
|
2484 |
#設置執行不正常
|
|
|
2485 |
$result["status"]="false";
|
|
|
2486 |
|
|
|
2487 |
#設置執行錯誤
|
|
|
2488 |
$result["error"]=$callShell;
|
|
|
2489 |
|
|
|
2490 |
#回傳結果
|
|
|
2491 |
return $result;
|
|
|
2492 |
|
|
|
2493 |
}#if end
|
|
|
2494 |
|
|
|
2495 |
#範例輸出:
|
|
|
2496 |
#Script started on Sat 05 Nov 2016 06:08:31 PM CST
|
|
|
2497 |
#Password: valid
|
|
|
2498 |
|
|
|
2499 |
#如果輸出 "valid"
|
|
|
2500 |
if($callShell["output"][1]=="Password: valid"){
|
|
|
2501 |
|
|
|
2502 |
#代表使用者密碼正確
|
|
|
2503 |
|
|
|
2504 |
#設置執行正常
|
|
|
2505 |
$result["status"]="true";
|
|
|
2506 |
|
|
|
2507 |
#設置使用者驗證失敗
|
|
|
2508 |
$result["valid"]="true";
|
|
|
2509 |
|
|
|
2510 |
#回傳結果
|
|
|
2511 |
return $result;
|
|
|
2512 |
|
|
|
2513 |
}#if end
|
|
|
2514 |
|
|
|
2515 |
#反之如果是
|
|
|
2516 |
else if($callShell["output"][1]="Password: su: Authentication failure"){
|
|
|
2517 |
|
|
|
2518 |
#代表使用者密碼不正確
|
|
|
2519 |
$result["status"]="true";
|
|
|
2520 |
|
|
|
2521 |
#設置使用者驗證失敗
|
|
|
2522 |
$result["valid"]="false";
|
|
|
2523 |
|
|
|
2524 |
#設置使用者不存在的警告
|
|
|
2525 |
$result["warning"][]="使用者 \"".$conf["username"]."\" 的密碼不為 \"".$conf["password"]."\" !";
|
|
|
2526 |
|
|
|
2527 |
#回傳結果
|
|
|
2528 |
return $result;
|
|
|
2529 |
|
|
|
2530 |
}#if end
|
|
|
2531 |
|
|
|
2532 |
#反之
|
|
|
2533 |
else{
|
|
|
2534 |
|
|
|
2535 |
#設置執行不正常
|
|
|
2536 |
$result["status"]="false";
|
|
|
2537 |
|
|
|
2538 |
#設置錯誤訊息
|
|
|
2539 |
$result["error"]=$callShell;
|
|
|
2540 |
$result["error"][]="非預期的輸出結果!";
|
|
|
2541 |
|
|
|
2542 |
#回傳結果
|
|
|
2543 |
return $result;
|
|
|
2544 |
|
|
|
2545 |
}#else end
|
|
|
2546 |
|
|
|
2547 |
#設置執行不正常
|
|
|
2548 |
$result["status"]="false";
|
|
|
2549 |
|
|
|
2550 |
#設置錯誤訊息
|
|
|
2551 |
$result["error"][]="非預期的結果!";
|
|
|
2552 |
|
|
|
2553 |
#回傳結果
|
|
|
2554 |
return $result;
|
|
|
2555 |
|
|
|
2556 |
}#function validUser end
|
|
|
2557 |
|
|
|
2558 |
/*
|
|
|
2559 |
#函式說明:
|
|
|
2560 |
#用php的password_hash方法來單向加密密碼.
|
|
|
2561 |
#回傳結果:
|
|
|
2562 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2563 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2564 |
#$result["function"],當前執行的函式名稱.
|
|
|
2565 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
2566 |
#必填參數:
|
|
|
2567 |
#無
|
|
|
2568 |
#可省略參數:
|
|
|
2569 |
#$conf["password"],字串,要加密的密碼,預設為"qbpwcf".
|
|
|
2570 |
#$conf["password"]="qbpwcf";
|
| 171 |
liveuser |
2571 |
#參考資料:
|
|
|
2572 |
#無.
|
| 1 |
liveuser |
2573 |
#備註:
|
|
|
2574 |
#無.
|
|
|
2575 |
*/
|
|
|
2576 |
public static function encodePassword(&$conf=array()){
|
|
|
2577 |
|
|
|
2578 |
#初始化要回傳的結果
|
|
|
2579 |
$result=array();
|
|
|
2580 |
|
|
|
2581 |
#取得當前執行的函數名稱
|
|
|
2582 |
$result["function"]=__FUNCTION__;
|
|
|
2583 |
|
|
|
2584 |
#如果沒有參數
|
|
|
2585 |
if(func_num_args()==0){
|
|
|
2586 |
|
|
|
2587 |
#設置執行失敗
|
|
|
2588 |
$result["status"]="false";
|
|
|
2589 |
|
|
|
2590 |
#設置執行錯誤訊息
|
|
|
2591 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2592 |
|
|
|
2593 |
#回傳結果
|
|
|
2594 |
return $result;
|
|
|
2595 |
|
|
|
2596 |
}#if end
|
|
|
2597 |
|
|
|
2598 |
#取得參數
|
|
|
2599 |
$result["argu"]=$conf;
|
|
|
2600 |
|
|
|
2601 |
#如果 $conf 不為陣列
|
|
|
2602 |
if(gettype($conf)!=="array"){
|
|
|
2603 |
|
|
|
2604 |
#設置執行失敗
|
|
|
2605 |
$result["status"]="false";
|
|
|
2606 |
|
|
|
2607 |
#設置執行錯誤訊息
|
|
|
2608 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2609 |
|
|
|
2610 |
#如果傳入的參數為 null
|
|
|
2611 |
if($conf===null){
|
|
|
2612 |
|
|
|
2613 |
#設置執行錯誤訊息
|
|
|
2614 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2615 |
|
|
|
2616 |
}#if end
|
|
|
2617 |
|
|
|
2618 |
#回傳結果
|
|
|
2619 |
return $result;
|
|
|
2620 |
|
|
|
2621 |
}#if end
|
|
|
2622 |
|
|
|
2623 |
#檢查參數
|
|
|
2624 |
#函式說明:
|
|
|
2625 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2626 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2627 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2628 |
#$result["function"],當前執行的函式名稱.
|
|
|
2629 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2630 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2631 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2632 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2633 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2634 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2635 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2636 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2637 |
#必填寫的參數:
|
|
|
2638 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2639 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2640 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2641 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2642 |
#可以省略的參數:
|
|
|
2643 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2644 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
2645 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2646 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
2647 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2648 |
#$conf["canBeEmptyString"]="false";
|
|
|
2649 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2650 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2651 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2652 |
#$conf["canBeEmpty"]=array();
|
|
|
2653 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2654 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2655 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2656 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
|
|
|
2657 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2658 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2659 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2660 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
|
|
|
2661 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2662 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2663 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2664 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2665 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2666 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2667 |
#參考資料來源:
|
|
|
2668 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2669 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2670 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2671 |
|
|
|
2672 |
#如果驗證失敗
|
|
|
2673 |
if($checkArguments["status"]==="false"){
|
|
|
2674 |
|
|
|
2675 |
#設置執行失敗
|
|
|
2676 |
$result["status"]="false";
|
|
|
2677 |
|
|
|
2678 |
#設置錯誤訊息
|
|
|
2679 |
$result["error"]=$checkArguments;
|
|
|
2680 |
|
|
|
2681 |
#回傳結果
|
|
|
2682 |
return $result;
|
|
|
2683 |
|
|
|
2684 |
}#if end
|
|
|
2685 |
|
|
|
2686 |
#如果驗證不成功
|
|
|
2687 |
if($checkArguments["passed"]==="false"){
|
|
|
2688 |
|
|
|
2689 |
#設置執行失敗
|
|
|
2690 |
$result["status"]="false";
|
|
|
2691 |
|
|
|
2692 |
#設置錯誤訊息
|
|
|
2693 |
$result["error"]=$checkArguments;
|
|
|
2694 |
|
|
|
2695 |
#回傳結果
|
|
|
2696 |
return $result;
|
|
|
2697 |
|
|
|
2698 |
}#if end
|
|
|
2699 |
|
|
|
2700 |
#取得加密好的密碼
|
|
|
2701 |
$result["content"]=password_hash($conf["password"],PASSWORD_DEFAULT);
|
|
|
2702 |
|
|
|
2703 |
#設置執行正常
|
|
|
2704 |
$result["status"]="true";
|
|
|
2705 |
|
|
|
2706 |
#回傳結果
|
|
|
2707 |
return $result;
|
|
|
2708 |
|
|
|
2709 |
}#function encodePassword end
|
|
|
2710 |
|
|
|
2711 |
/*
|
|
|
2712 |
#函式說明:
|
|
|
2713 |
#用php的password_verify方法來驗證密碼是否正確.
|
|
|
2714 |
#回傳結果:
|
|
|
2715 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2716 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2717 |
#$result["function"],當前執行的函式名稱.
|
|
|
2718 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
2719 |
#必填參數:
|
|
|
2720 |
#$conf["input"],字串,要檢查是否正確的待驗證密碼.
|
|
|
2721 |
$conf["input"]="";
|
|
|
2722 |
#$conf["password"],字串,透過encodePassword加密後的密碼.
|
|
|
2723 |
$conf["password"]="";
|
|
|
2724 |
#可省略參數:
|
|
|
2725 |
#無.
|
| 171 |
liveuser |
2726 |
#參考資料:
|
|
|
2727 |
#無.
|
| 1 |
liveuser |
2728 |
#備註:
|
|
|
2729 |
#無.
|
|
|
2730 |
*/
|
|
|
2731 |
public static function validPassword(&$conf=array()){
|
|
|
2732 |
|
|
|
2733 |
#初始化要回傳的結果
|
|
|
2734 |
$result=array();
|
|
|
2735 |
|
|
|
2736 |
#取得當前執行的函數名稱
|
|
|
2737 |
$result["function"]=__FUNCTION__;
|
|
|
2738 |
|
|
|
2739 |
#如果沒有參數
|
|
|
2740 |
if(func_num_args()==0){
|
|
|
2741 |
|
|
|
2742 |
#設置執行失敗
|
|
|
2743 |
$result["status"]="false";
|
|
|
2744 |
|
|
|
2745 |
#設置執行錯誤訊息
|
|
|
2746 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2747 |
|
|
|
2748 |
#回傳結果
|
|
|
2749 |
return $result;
|
|
|
2750 |
|
|
|
2751 |
}#if end
|
|
|
2752 |
|
|
|
2753 |
#取得參數
|
|
|
2754 |
$result["argu"]=$conf;
|
|
|
2755 |
|
|
|
2756 |
#如果 $conf 不為陣列
|
|
|
2757 |
if(gettype($conf)!=="array"){
|
|
|
2758 |
|
|
|
2759 |
#設置執行失敗
|
|
|
2760 |
$result["status"]="false";
|
|
|
2761 |
|
|
|
2762 |
#設置執行錯誤訊息
|
|
|
2763 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2764 |
|
|
|
2765 |
#如果傳入的參數為 null
|
|
|
2766 |
if($conf===null){
|
|
|
2767 |
|
|
|
2768 |
#設置執行錯誤訊息
|
|
|
2769 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2770 |
|
|
|
2771 |
}#if end
|
|
|
2772 |
|
|
|
2773 |
#回傳結果
|
|
|
2774 |
return $result;
|
|
|
2775 |
|
|
|
2776 |
}#if end
|
|
|
2777 |
|
|
|
2778 |
#檢查參數
|
|
|
2779 |
#函式說明:
|
|
|
2780 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2781 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2782 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2783 |
#$result["function"],當前執行的函式名稱.
|
|
|
2784 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2785 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2786 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2787 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2788 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2789 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2790 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2791 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2792 |
#必填寫的參數:
|
|
|
2793 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2794 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2795 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2796 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2797 |
#可以省略的參數:
|
|
|
2798 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2799 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","password");
|
|
|
2800 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2801 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2802 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2803 |
#$conf["canBeEmptyString"]="false";
|
|
|
2804 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2805 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2806 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2807 |
#$conf["canBeEmpty"]=array();
|
|
|
2808 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2809 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2810 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2811 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
|
|
|
2812 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2813 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2814 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2815 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
|
|
|
2816 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2817 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2818 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2819 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2820 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2821 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2822 |
#參考資料來源:
|
|
|
2823 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2824 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2825 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2826 |
|
|
|
2827 |
#如果驗證失敗
|
|
|
2828 |
if($checkArguments["status"]==="false"){
|
|
|
2829 |
|
|
|
2830 |
#設置執行失敗
|
|
|
2831 |
$result["status"]="false";
|
|
|
2832 |
|
|
|
2833 |
#設置錯誤訊息
|
|
|
2834 |
$result["error"]=$checkArguments;
|
|
|
2835 |
|
|
|
2836 |
#回傳結果
|
|
|
2837 |
return $result;
|
|
|
2838 |
|
|
|
2839 |
}#if end
|
|
|
2840 |
|
|
|
2841 |
#如果驗證不成功
|
|
|
2842 |
if($checkArguments["passed"]==="false"){
|
|
|
2843 |
|
|
|
2844 |
#設置執行失敗
|
|
|
2845 |
$result["status"]="false";
|
|
|
2846 |
|
|
|
2847 |
#設置錯誤訊息
|
|
|
2848 |
$result["error"]=$checkArguments;
|
|
|
2849 |
|
|
|
2850 |
#回傳結果
|
|
|
2851 |
return $result;
|
|
|
2852 |
|
|
|
2853 |
}#if end
|
|
|
2854 |
|
|
|
2855 |
#儲存驗證後的結果
|
|
|
2856 |
$pass=password_verify($conf["input"],$conf["password"]);
|
|
|
2857 |
|
|
|
2858 |
#如果驗證成功
|
|
|
2859 |
if($pass){
|
|
|
2860 |
|
|
|
2861 |
#設置驗證成功
|
|
|
2862 |
$result["passed"]="true";
|
|
|
2863 |
|
|
|
2864 |
}#if end
|
|
|
2865 |
|
|
|
2866 |
#反之驗證失敗
|
|
|
2867 |
else{
|
|
|
2868 |
|
|
|
2869 |
#設置驗證成功
|
|
|
2870 |
$result["passed"]="false";
|
|
|
2871 |
|
|
|
2872 |
}#else end
|
|
|
2873 |
|
|
|
2874 |
#設置執行正常
|
|
|
2875 |
$result["status"]="true";
|
|
|
2876 |
|
|
|
2877 |
#回傳結果
|
|
|
2878 |
return $result;
|
|
|
2879 |
|
|
|
2880 |
}#function validPassword end
|
|
|
2881 |
|
|
|
2882 |
/*
|
|
|
2883 |
#函式說明:
|
|
|
2884 |
#產生 google reCAPTCH 的使用者界面,若session變數中有google_reCAPTCHA_pass變數且dns相同則不顯示.
|
|
|
2885 |
#回傳結果:
|
|
|
2886 |
#$result["status"],執行正常與否,"false"代表不正常;"true"代表正常.
|
|
|
2887 |
#$result["error"],錯誤訊息陣列.
|
|
|
2888 |
#$result["content"],語法.
|
|
|
2889 |
#$result["function"],函式名稱.
|
|
|
2890 |
#$result["userRequest"],當前網址.
|
|
|
2891 |
#必填參數:
|
|
|
2892 |
#$conf["sitekey"],字串,要用 recaptcha 的 site key.
|
|
|
2893 |
#$conf["sitekey"]="";
|
|
|
2894 |
#可省略參數:
|
|
|
2895 |
#無
|
|
|
2896 |
#參考資料:
|
|
|
2897 |
#https://developers.google.com/recaptcha/
|
|
|
2898 |
#https://www.google.com/recaptcha/admin
|
|
|
2899 |
#備註:
|
|
|
2900 |
#可透過 js document.getElementById('g-recaptcha-response').value 來取得 response, "" 代表無效;有值代表有效.
|
|
|
2901 |
#如果有使用 javascript::qbpwcfJavaScript 則用 getGoogle_reCAPTCHA_res.call(this) 可取得 response, 'false' 代表無效; 'true' 代表有效.
|
|
|
2902 |
#監控完成 reCAPTCHA client 驗證的事件,完成要觸發 getGoogle_reCAPTCHA_res.call(this) ,目前觸發的效果不是很及時。
|
|
|
2903 |
#如果連線不到 google 則不顯示?
|
|
|
2904 |
*/
|
|
|
2905 |
public static function gl_reCAPTCHA_client(&$conf=array()){
|
|
|
2906 |
|
|
|
2907 |
#初始化要回傳的結果
|
|
|
2908 |
$result=array();
|
|
|
2909 |
|
|
|
2910 |
#取得當前執行的函數名稱
|
|
|
2911 |
$result["function"]=__FUNCTION__;
|
|
|
2912 |
|
|
|
2913 |
#如果沒有參數
|
|
|
2914 |
if(func_num_args()==0){
|
|
|
2915 |
|
|
|
2916 |
#設置執行失敗
|
|
|
2917 |
$result["status"]="false";
|
|
|
2918 |
|
|
|
2919 |
#設置執行錯誤訊息
|
|
|
2920 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2921 |
|
|
|
2922 |
#回傳結果
|
|
|
2923 |
return $result;
|
|
|
2924 |
|
|
|
2925 |
}#if end
|
|
|
2926 |
|
|
|
2927 |
#取得參數
|
|
|
2928 |
$result["argu"]=$conf;
|
|
|
2929 |
|
|
|
2930 |
#如果 $conf 不為陣列
|
|
|
2931 |
if(gettype($conf)!=="array"){
|
|
|
2932 |
|
|
|
2933 |
#設置執行失敗
|
|
|
2934 |
$result["status"]="false";
|
|
|
2935 |
|
|
|
2936 |
#設置執行錯誤訊息
|
|
|
2937 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2938 |
|
|
|
2939 |
#如果傳入的參數為 null
|
|
|
2940 |
if($conf===null){
|
|
|
2941 |
|
|
|
2942 |
#設置執行錯誤訊息
|
|
|
2943 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2944 |
|
|
|
2945 |
}#if end
|
|
|
2946 |
|
|
|
2947 |
#回傳結果
|
|
|
2948 |
return $result;
|
|
|
2949 |
|
|
|
2950 |
}#if end
|
|
|
2951 |
|
|
|
2952 |
#檢查參數
|
|
|
2953 |
#函式說明:
|
|
|
2954 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2955 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2956 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2957 |
#$result["function"],當前執行的函式名稱.
|
|
|
2958 |
#$result["argu"],設置給予的參數.
|
|
|
2959 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2960 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2961 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2962 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2963 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2964 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2965 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2966 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2967 |
#必填寫的參數:
|
|
|
2968 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2969 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2970 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2971 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2972 |
#可以省略的參數:
|
|
|
2973 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2974 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sitekey");
|
|
|
2975 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2976 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2977 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2978 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2979 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2980 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2981 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2982 |
#$conf["canBeEmpty"]=array();
|
|
|
2983 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2984 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2985 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2986 |
#$conf["skipableVariableName"]=array();
|
|
|
2987 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2988 |
#$conf["skipableVariableType"]=array();
|
|
|
2989 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2990 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
2991 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2992 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2993 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2994 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2995 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2996 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2997 |
#參考資料來源:
|
|
|
2998 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2999 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3000 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3001 |
|
|
|
3002 |
#如果檢查參數失敗
|
|
|
3003 |
if($checkArguments["status"]==="false"){
|
|
|
3004 |
|
|
|
3005 |
#設置執行錯誤
|
|
|
3006 |
$result["status"]="false";
|
|
|
3007 |
|
|
|
3008 |
#設置執行錯誤訊息
|
|
|
3009 |
$result["error"]=$checkArguments;
|
|
|
3010 |
|
|
|
3011 |
#回傳結果
|
|
|
3012 |
return $result;
|
|
|
3013 |
|
|
|
3014 |
}#if end
|
|
|
3015 |
|
|
|
3016 |
#如果檢查參數不通過
|
|
|
3017 |
if($checkArguments["passed"]==="false"){
|
|
|
3018 |
|
|
|
3019 |
#設置執行錯誤
|
|
|
3020 |
$result["status"]="false";
|
|
|
3021 |
|
|
|
3022 |
#設置執行錯誤訊息
|
|
|
3023 |
$result["error"]=$checkArguments;
|
|
|
3024 |
|
|
|
3025 |
#回傳結果
|
|
|
3026 |
return $result;
|
|
|
3027 |
|
|
|
3028 |
}#if end
|
|
|
3029 |
|
|
|
3030 |
#初始化要回傳的 content
|
|
|
3031 |
$result["content"]="";
|
|
|
3032 |
|
|
|
3033 |
#取得當前的url
|
|
|
3034 |
#函式說明:
|
|
|
3035 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
3036 |
#回傳的結果:
|
|
|
3037 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
3038 |
#$result["error"],錯誤訊息.
|
|
|
3039 |
#$result["function"],檔前執行的函數名稱.
|
|
|
3040 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
3041 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
3042 |
#$result["userIp"],爲使用者的IP
|
|
|
3043 |
#$result["serverIp"],為伺服器的IP
|
|
|
3044 |
#$result["scheme"],通訊協定
|
|
|
3045 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
3046 |
#$result["requestUri"],爲使用者要求的網址
|
|
|
3047 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
3048 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
3049 |
#$result["phpUser"],運行該php的使用者帳戶.
|
|
|
3050 |
#必填參數:
|
|
|
3051 |
$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
|
|
|
3052 |
#可省略參數:
|
|
|
3053 |
#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
|
|
|
3054 |
#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
|
|
|
3055 |
#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
3056 |
#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
3057 |
#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
3058 |
#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
3059 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
|
|
|
3060 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
3061 |
#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
|
|
|
3062 |
#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
3063 |
#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
3064 |
#參考資料:
|
|
|
3065 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
3066 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
3067 |
$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
|
|
|
3068 |
unset($conf["csInformation::getConnectionInfo"]);
|
|
|
3069 |
|
|
|
3070 |
#如果失敗
|
|
|
3071 |
if($getConnectionInfo["status"]==="false"){
|
|
|
3072 |
|
|
|
3073 |
#設置執行失敗的識別
|
|
|
3074 |
$result["status"]="false";
|
|
|
3075 |
|
|
|
3076 |
#設置執行錯誤訊息
|
|
|
3077 |
$result["error"]=$getConnectionInfo;
|
|
|
3078 |
|
|
|
3079 |
#回傳結果
|
|
|
3080 |
return $result;
|
|
|
3081 |
|
|
|
3082 |
}#if end
|
|
|
3083 |
|
|
|
3084 |
#初始化port字串
|
|
|
3085 |
$port="";
|
|
|
3086 |
|
|
|
3087 |
#如果不是正常的80port,443port
|
|
|
3088 |
if($getConnectionInfo["serverPort"]!=="443" && $getConnectionInfo["serverPort"]!=="80"){
|
|
|
3089 |
|
|
|
3090 |
#指定port
|
|
|
3091 |
$port=":".$getConnectionInfo["serverPort"];
|
|
|
3092 |
|
|
|
3093 |
}#if end
|
|
|
3094 |
|
|
|
3095 |
#另存 request
|
|
|
3096 |
$userRequest=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$port.$getConnectionInfo["requestUri"];
|
|
|
3097 |
|
|
|
3098 |
#記錄當前的網址
|
|
|
3099 |
$result["userRequest"]=$userRequest;
|
|
|
3100 |
|
|
|
3101 |
#函式說明:
|
|
|
3102 |
#檢查是否擁有透過gl_reCAPTCHA_server授權的session網址記錄.
|
|
|
3103 |
#回傳結果:
|
|
|
3104 |
#$result["status"],執行正常與否,"false"代表不正常;"true"代表正常.
|
|
|
3105 |
#$result["error"],錯誤訊息陣列.
|
|
|
3106 |
#$result["function"],函式名稱.
|
|
|
3107 |
#$result["passed"],"true"代表通過檢查,"false"代表沒有通過檢查.
|
|
|
3108 |
#必填參數:
|
|
|
3109 |
#$conf["url"],字串,要有什麼的網址才通過檢查
|
|
|
3110 |
$conf["authenticate::gl_reCAPTCH_authCheck"]["url"]=$userRequest;
|
|
|
3111 |
$gl_reCAPTCH_authCheck=authenticate::gl_reCAPTCH_authCheck($conf["authenticate::gl_reCAPTCH_authCheck"]);
|
|
|
3112 |
unset($conf["authenticate::gl_reCAPTCH_authCheck"]);
|
|
|
3113 |
|
|
|
3114 |
#如果檢查失敗
|
|
|
3115 |
if($gl_reCAPTCH_authCheck["status"]==="false"){
|
|
|
3116 |
|
|
|
3117 |
#設置執行失敗的識別
|
|
|
3118 |
$result["status"]="false";
|
|
|
3119 |
|
|
|
3120 |
#設置執行錯誤訊息
|
|
|
3121 |
$result["error"]=$gl_reCAPTCH_authCheck;
|
|
|
3122 |
|
|
|
3123 |
#回傳結果
|
|
|
3124 |
return $result;
|
|
|
3125 |
|
|
|
3126 |
}#if end
|
|
|
3127 |
|
|
|
3128 |
#如果已經認證完畢了
|
|
|
3129 |
if($gl_reCAPTCH_authCheck["passed"]==="true"){
|
|
|
3130 |
|
|
|
3131 |
#設置執行正常
|
|
|
3132 |
$result["status"]="true";
|
|
|
3133 |
|
|
|
3134 |
#回傳結果
|
|
|
3135 |
return $result;
|
|
|
3136 |
|
|
|
3137 |
}#if end
|
|
|
3138 |
|
|
|
3139 |
#嵌入 google recaptcha
|
|
|
3140 |
$result["content"]=$result["content"]."<script src='https://www.google.com/recaptcha/api.js'></script>";
|
|
|
3141 |
|
|
|
3142 |
#放置 recaptcha 的效果
|
|
|
3143 |
$result["content"]=$result["content"]."<div class=\"g-recaptcha\" data-sitekey=\"".$conf["sitekey"]."\"></div>";
|
|
|
3144 |
|
|
|
3145 |
#設置執行正常
|
|
|
3146 |
$result["status"]="true";
|
|
|
3147 |
|
|
|
3148 |
#回傳結果
|
|
|
3149 |
return $result;
|
|
|
3150 |
|
|
|
3151 |
}#function gl_reCAPTCH_client end
|
|
|
3152 |
|
|
|
3153 |
/*
|
|
|
3154 |
#函式說明:
|
|
|
3155 |
#驗證 google reCAPTCH 回傳的驗證碼,當有post的response,key,val時,會進行處理,key為建立session變數的名稱,val為其變數內容.
|
|
|
3156 |
#回傳結果:
|
|
|
3157 |
#$result["status"],執行正常與否,"false"代表不正常;"true"代表正常.
|
|
|
3158 |
#$result["error"],錯誤訊息陣列.
|
|
|
3159 |
#$result["function"],函式名稱.
|
|
|
3160 |
#$result["passed"],"true"代表通過驗證,"false"代表沒有通過驗證.
|
|
|
3161 |
#必填參數:
|
|
|
3162 |
#$conf["secret"],字串,recaptcha 上對應 site 的 secret.
|
|
|
3163 |
#$conf["secret"]="";
|
|
|
3164 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
3165 |
#$conf["fileArgu"]=__FILE__;
|
|
|
3166 |
#可省略參數:
|
| 171 |
liveuser |
3167 |
#無.
|
| 1 |
liveuser |
3168 |
#參考資料:
|
|
|
3169 |
#https://developers.google.com/recaptcha/docs/verify
|
|
|
3170 |
#備註:
|
|
|
3171 |
#無.
|
|
|
3172 |
*/
|
|
|
3173 |
public static function gl_reCAPTCHA_server(&$conf=array()){
|
|
|
3174 |
|
|
|
3175 |
#初始化要回傳的結果
|
|
|
3176 |
$result=array();
|
|
|
3177 |
|
|
|
3178 |
#取得當前執行的函數名稱
|
|
|
3179 |
$result["function"]=__FUNCTION__;
|
|
|
3180 |
|
|
|
3181 |
#如果沒有參數
|
|
|
3182 |
if(func_num_args()==0){
|
|
|
3183 |
|
|
|
3184 |
#設置執行失敗
|
|
|
3185 |
$result["status"]="false";
|
|
|
3186 |
|
|
|
3187 |
#設置執行錯誤訊息
|
|
|
3188 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3189 |
|
|
|
3190 |
#印出結果
|
|
|
3191 |
return $result;
|
|
|
3192 |
|
|
|
3193 |
}#if end
|
|
|
3194 |
|
|
|
3195 |
#取得參數
|
|
|
3196 |
$result["argu"]=$conf;
|
|
|
3197 |
|
|
|
3198 |
#如果 $conf 不為陣列
|
|
|
3199 |
if(gettype($conf)!=="array"){
|
|
|
3200 |
|
|
|
3201 |
#設置執行失敗
|
|
|
3202 |
$result["status"]="false";
|
|
|
3203 |
|
|
|
3204 |
#設置執行錯誤訊息
|
|
|
3205 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3206 |
|
|
|
3207 |
#如果傳入的參數為 null
|
|
|
3208 |
if($conf===null){
|
|
|
3209 |
|
|
|
3210 |
#設置執行錯誤訊息
|
|
|
3211 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3212 |
|
|
|
3213 |
}#if end
|
|
|
3214 |
|
|
|
3215 |
#印出結果
|
|
|
3216 |
return $result;
|
|
|
3217 |
|
|
|
3218 |
}#if end
|
|
|
3219 |
|
|
|
3220 |
#檢查參數
|
|
|
3221 |
#函式說明:
|
|
|
3222 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3223 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3224 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3225 |
#$result["function"],當前執行的函式名稱.
|
|
|
3226 |
#$result["argu"],設置給予的參數.
|
|
|
3227 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3228 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3229 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3230 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3231 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3232 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3233 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3234 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3235 |
#必填寫的參數:
|
|
|
3236 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3237 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3238 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3239 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3240 |
#可以省略的參數:
|
|
|
3241 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3242 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("secret","fileArgu");
|
|
|
3243 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3244 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3245 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3246 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3247 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3248 |
#$conf["canNotBeEmpty"]=array();
|
|
|
3249 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3250 |
#$conf["canBeEmpty"]=array();
|
|
|
3251 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3252 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3253 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3254 |
#$conf["skipableVariableName"]=array();
|
|
|
3255 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3256 |
#$conf["skipableVariableType"]=array();
|
|
|
3257 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3258 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3259 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3260 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3261 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3262 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3263 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3264 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3265 |
#參考資料來源:
|
|
|
3266 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3267 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3268 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3269 |
|
|
|
3270 |
#如果檢查參數失敗
|
|
|
3271 |
if($checkArguments["status"]==="false"){
|
|
|
3272 |
|
|
|
3273 |
#設置執行錯誤
|
|
|
3274 |
$result["status"]="false";
|
|
|
3275 |
|
|
|
3276 |
#設置執行錯誤訊息
|
|
|
3277 |
$result["error"]=$checkArguments;
|
|
|
3278 |
|
|
|
3279 |
#印出結果
|
|
|
3280 |
return $result;
|
|
|
3281 |
|
|
|
3282 |
}#if end
|
|
|
3283 |
|
|
|
3284 |
#如果檢查參數不通過
|
|
|
3285 |
if($checkArguments["passed"]==="false"){
|
|
|
3286 |
|
|
|
3287 |
#設置執行錯誤
|
|
|
3288 |
$result["status"]="false";
|
|
|
3289 |
|
|
|
3290 |
#設置執行錯誤訊息
|
|
|
3291 |
$result["error"]=$checkArguments;
|
|
|
3292 |
|
|
|
3293 |
#印出結果
|
|
|
3294 |
return $result;
|
|
|
3295 |
|
|
|
3296 |
}#if end
|
|
|
3297 |
|
|
|
3298 |
#函式說明:
|
|
|
3299 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
3300 |
#回傳的結果:
|
|
|
3301 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
3302 |
#$result["error"],錯誤訊息陣列.
|
|
|
3303 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
3304 |
#$result["warning"],警告訊息陣列.
|
|
|
3305 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
3306 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
3307 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
3308 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
3309 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
3310 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
3311 |
#必填的參數:
|
|
|
3312 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
3313 |
$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="post";
|
|
|
3314 |
#可省略參數:
|
|
|
3315 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
3316 |
#$conf["allowGet"]="true";
|
|
|
3317 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
3318 |
#$conf["limitPrePage"]=array("");
|
|
|
3319 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
3320 |
#$conf["transferLocation"]="";
|
|
|
3321 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
3322 |
#$conf["ignore"]=array();
|
|
|
3323 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
3324 |
$conf["form::responseMultiInputDataSecurityEnhance"]["correctCharacter"]="false";
|
|
|
3325 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
3326 |
$conf["form::responseMultiInputDataSecurityEnhance"]["checkedVarName"]=array("response","key","val");
|
|
|
3327 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
3328 |
$conf["form::responseMultiInputDataSecurityEnhance"]["canBeEmptyString"]="false";
|
|
|
3329 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
3330 |
#$conf["form::responseMultiInputDataSecurityEnhance"]["sessionNameArray"]=array();
|
|
|
3331 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
3332 |
#$conf["form::responseMultiInputDataSecurityEnhance"]["unsetSessionArray"]=array();
|
|
|
3333 |
#參考資料來源:
|
|
|
3334 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
3335 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
3336 |
#備註:
|
|
|
3337 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
3338 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
3339 |
unset($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
3340 |
|
|
|
3341 |
#如果執行失敗
|
|
|
3342 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
3343 |
|
|
|
3344 |
#設置執行錯誤
|
|
|
3345 |
$result["status"]="false";
|
|
|
3346 |
|
|
|
3347 |
#設置執行錯誤訊息
|
|
|
3348 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
3349 |
|
|
|
3350 |
#印出結果
|
|
|
3351 |
return $result;
|
|
|
3352 |
|
|
|
3353 |
}#if end
|
|
|
3354 |
|
|
|
3355 |
#如果檢查不通過
|
|
|
3356 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
3357 |
|
|
|
3358 |
#設置執行錯誤
|
|
|
3359 |
$result["status"]="false";
|
|
|
3360 |
|
|
|
3361 |
#設置執行錯誤訊息
|
|
|
3362 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
3363 |
|
|
|
3364 |
#印出結果
|
|
|
3365 |
return $result;
|
|
|
3366 |
|
|
|
3367 |
}#if end
|
|
|
3368 |
|
|
|
3369 |
#函式說明:
|
|
|
3370 |
#運行curl cmd
|
|
|
3371 |
#回傳結果:
|
|
|
3372 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3373 |
#$result["error"],錯誤訊息陣列.
|
|
|
3374 |
#$result["function"],當前執行的函式名稱.
|
|
|
3375 |
#$result["content"],取得的回應內容.
|
|
|
3376 |
#$result["cmd"],執行的command
|
|
|
3377 |
#必填參數:
|
|
|
3378 |
#$conf["url"],字串,目標url.
|
|
|
3379 |
$conf["catchWebContent::curlCmd"]["url"]="https://www.google.com/recaptcha/api/siteverify";
|
|
|
3380 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3381 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3382 |
#可省略參數:
|
|
|
3383 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
3384 |
#$conf["header"]=array();
|
|
|
3385 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
3386 |
$conf["catchWebContent::curlCmd"]["allowAnySSLcertificate"]="false";
|
|
|
3387 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
3388 |
$conf["catchWebContent::curlCmd"]["postVar"]=array("secret"=>$conf["secret"],"response"=>$responseMultiInputDataSecurityEnhance["inputDataContent"]["response"]);
|
|
|
3389 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
3390 |
#$conf["urlEncode"]="false";
|
|
|
3391 |
#備註:
|
|
|
3392 |
#僅能在命令列下執行.
|
|
|
3393 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
3394 |
unset($conf["catchWebContent::curlCmd"]["catchWebContent::curlCmd"]);
|
|
|
3395 |
|
|
|
3396 |
#如果執行失敗
|
|
|
3397 |
if($curlCmd["status"]==="false"){
|
|
|
3398 |
|
|
|
3399 |
#設置執行錯誤
|
|
|
3400 |
$result["status"]="false";
|
|
|
3401 |
|
|
|
3402 |
#設置執行錯誤訊息
|
|
|
3403 |
$result["error"]=$curlCmd;
|
|
|
3404 |
|
|
|
3405 |
#印出結果
|
|
|
3406 |
return $result;
|
|
|
3407 |
|
|
|
3408 |
}#if end
|
|
|
3409 |
|
|
|
3410 |
/*
|
|
|
3411 |
應該會回傳json:
|
|
|
3412 |
{
|
|
|
3413 |
"success": true|false,
|
|
|
3414 |
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
|
|
|
3415 |
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
|
|
|
3416 |
"error-codes": [...] // optional
|
|
|
3417 |
}
|
|
|
3418 |
*/
|
|
|
3419 |
|
|
|
3420 |
#初始化回應的json字串
|
|
|
3421 |
$jsonStr="";
|
|
|
3422 |
|
|
|
3423 |
#將多行回應組成單一字串
|
|
|
3424 |
foreach($curlCmd["content"] as $line){
|
|
|
3425 |
|
|
|
3426 |
#串接json字串
|
|
|
3427 |
$jsonStr=$jsonStr.$line;
|
|
|
3428 |
|
|
|
3429 |
}#foreach end
|
|
|
3430 |
|
|
|
3431 |
#將回應的json進行解析
|
|
|
3432 |
$res=json_decode($jsonStr);
|
|
|
3433 |
|
|
|
3434 |
#如果解析失敗
|
|
|
3435 |
if($res===false){
|
|
|
3436 |
|
|
|
3437 |
#設置執行錯誤
|
|
|
3438 |
$result["status"]="false";
|
|
|
3439 |
|
|
|
3440 |
#設置執行錯誤訊息
|
|
|
3441 |
$result["error"]=$res;
|
|
|
3442 |
|
|
|
3443 |
#印出結果
|
|
|
3444 |
return $result;
|
|
|
3445 |
|
|
|
3446 |
}#if end
|
|
|
3447 |
|
|
|
3448 |
#如果驗證成功
|
|
|
3449 |
if($res->success===true || $res->success==="true"){
|
|
|
3450 |
|
|
|
3451 |
#設置執行正常
|
|
|
3452 |
$result["status"]="true";
|
|
|
3453 |
|
|
|
3454 |
#設置通過驗證
|
|
|
3455 |
$result["passed"]="true";
|
|
|
3456 |
|
|
|
3457 |
#將 $_POST["key"] 用 . 分割成陣列
|
|
|
3458 |
#函式說明:
|
|
|
3459 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
3460 |
#回傳結果:
|
|
|
3461 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3462 |
#$result["error"],錯誤訊息陣列
|
|
|
3463 |
#$result["function"],當前執行的函數名稱.
|
|
|
3464 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
3465 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
3466 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
3467 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
3468 |
#必填的參數:
|
|
|
3469 |
$conf["stringProcess::spiltString"]["stringIn"]=$responseMultiInputDataSecurityEnhance["inputDataContent"]["key"];#要處理的字串。
|
|
|
3470 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
3471 |
#可省略參數:
|
|
|
3472 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
3473 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
3474 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
3475 |
unset($conf["stringProcess::spiltString"]);
|
|
|
3476 |
|
|
|
3477 |
#如果分割字串失敗
|
|
|
3478 |
if($spiltString["status"]==="false"){
|
|
|
3479 |
|
|
|
3480 |
#設置執行錯誤
|
|
|
3481 |
$result["status"]="false";
|
|
|
3482 |
|
|
|
3483 |
#設置執行錯誤訊息
|
|
|
3484 |
$result["error"]=$spiltString;
|
|
|
3485 |
|
|
|
3486 |
#印出結果
|
|
|
3487 |
return $result;
|
|
|
3488 |
|
|
|
3489 |
}#if end
|
|
|
3490 |
|
|
|
3491 |
#函式說明:
|
|
|
3492 |
#設置多個session變數的內容
|
|
|
3493 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
3494 |
#$result["error"],錯誤訊息.
|
|
|
3495 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
3496 |
#$result["content"],每個設置好的session變數資訊
|
|
|
3497 |
#$result["function"],當前執行的函數名稱.
|
|
|
3498 |
#$result["argu"],使用的參數.
|
|
|
3499 |
#必填參數:
|
|
|
3500 |
#$conf["key"],二維陣列,每個session的key名稱與層級.
|
|
|
3501 |
$conf["session::setMultiVal"]["key"]=array($spiltString["dataArray"]);
|
|
|
3502 |
#$conf["val"],陣列,每個指定的session變數內容.
|
|
|
3503 |
$conf["session::setMultiVal"]["val"]=array($responseMultiInputDataSecurityEnhance["inputDataContent"]["val"]);
|
|
|
3504 |
#可省略參數:
|
|
|
3505 |
#$conf["storeAsNotRepeatArray"],字串,"true"代表要將變數內容存成陣列,預設為"false".
|
|
|
3506 |
$conf["session::setMultiVal"]["storeAsNotRepeatArray"]="true";
|
|
|
3507 |
$setMultiVal=session::setMultiVal($conf["session::setMultiVal"]);
|
|
|
3508 |
unset($conf["session::setMultiVal"]);
|
|
|
3509 |
|
|
|
3510 |
#如果執行失敗
|
|
|
3511 |
if($setMultiVal["status"]==="false"){
|
|
|
3512 |
|
|
|
3513 |
#設置執行正常
|
|
|
3514 |
$result["status"]="false";
|
|
|
3515 |
|
|
|
3516 |
#設置執行錯誤訊息
|
|
|
3517 |
$result["error"]=$setMultiVal;
|
|
|
3518 |
|
|
|
3519 |
#印出結果
|
|
|
3520 |
return $result;
|
|
|
3521 |
|
|
|
3522 |
}#if end
|
|
|
3523 |
|
|
|
3524 |
#印出結果
|
|
|
3525 |
return $result;
|
|
|
3526 |
|
|
|
3527 |
}#if end
|
|
|
3528 |
|
|
|
3529 |
#反之驗證失敗
|
|
|
3530 |
else{
|
|
|
3531 |
|
|
|
3532 |
#設置執行正常
|
|
|
3533 |
$result["status"]="true";
|
|
|
3534 |
|
|
|
3535 |
#設置通過驗證
|
|
|
3536 |
$result["passed"]="false";
|
|
|
3537 |
|
|
|
3538 |
#設置警告訊息
|
|
|
3539 |
$result["warning"]=$res;
|
|
|
3540 |
|
|
|
3541 |
#印出結果
|
|
|
3542 |
return $result;
|
|
|
3543 |
|
|
|
3544 |
}#else end
|
|
|
3545 |
|
|
|
3546 |
}#function gl_reCAPTCH_server end
|
|
|
3547 |
|
|
|
3548 |
/*
|
|
|
3549 |
#函式說明:
|
|
|
3550 |
#檢查是否擁有透過gl_reCAPTCHA_server授權的session網址記錄.
|
|
|
3551 |
#回傳結果:
|
|
|
3552 |
#$result["status"],執行正常與否,"false"代表不正常;"true"代表正常.
|
|
|
3553 |
#$result["error"],錯誤訊息陣列.
|
|
|
3554 |
#$result["function"],函式名稱.
|
|
|
3555 |
#$result["passed"],"true"代表通過檢查,"false"代表沒有通過檢查.
|
|
|
3556 |
#必填參數:
|
|
|
3557 |
#$conf["url"],字串,要有什麼的網址才通過檢查
|
|
|
3558 |
$conf["url"]="";
|
|
|
3559 |
#可省略參數:
|
|
|
3560 |
#無.
|
| 171 |
liveuser |
3561 |
#參考資料:
|
|
|
3562 |
#無.
|
| 1 |
liveuser |
3563 |
#備註:
|
|
|
3564 |
#無.
|
|
|
3565 |
*/
|
|
|
3566 |
public static function gl_reCAPTCH_authCheck(&$conf=array()){
|
|
|
3567 |
|
|
|
3568 |
#初始化要回傳的結果
|
|
|
3569 |
$result=array();
|
|
|
3570 |
|
|
|
3571 |
#取得當前執行的函數名稱
|
|
|
3572 |
$result["function"]=__FUNCTION__;
|
|
|
3573 |
|
|
|
3574 |
#如果沒有參數
|
|
|
3575 |
if(func_num_args()==0){
|
|
|
3576 |
|
|
|
3577 |
#設置執行失敗
|
|
|
3578 |
$result["status"]="false";
|
|
|
3579 |
|
|
|
3580 |
#設置執行錯誤訊息
|
|
|
3581 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3582 |
|
|
|
3583 |
#印出結果
|
|
|
3584 |
return $result;
|
|
|
3585 |
|
|
|
3586 |
}#if end
|
|
|
3587 |
|
|
|
3588 |
#取得參數
|
|
|
3589 |
$result["argu"]=$conf;
|
|
|
3590 |
|
|
|
3591 |
#如果 $conf 不為陣列
|
|
|
3592 |
if(gettype($conf)!=="array"){
|
|
|
3593 |
|
|
|
3594 |
#設置執行失敗
|
|
|
3595 |
$result["status"]="false";
|
|
|
3596 |
|
|
|
3597 |
#設置執行錯誤訊息
|
|
|
3598 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3599 |
|
|
|
3600 |
#如果傳入的參數為 null
|
|
|
3601 |
if($conf===null){
|
|
|
3602 |
|
|
|
3603 |
#設置執行錯誤訊息
|
|
|
3604 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3605 |
|
|
|
3606 |
}#if end
|
|
|
3607 |
|
|
|
3608 |
#印出結果
|
|
|
3609 |
return $result;
|
|
|
3610 |
|
|
|
3611 |
}#if end
|
|
|
3612 |
|
|
|
3613 |
#檢查參數
|
|
|
3614 |
#函式說明:
|
|
|
3615 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3617 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3618 |
#$result["function"],當前執行的函式名稱.
|
|
|
3619 |
#$result["argu"],設置給予的參數.
|
|
|
3620 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3621 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3622 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3623 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3624 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3625 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3626 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3627 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3628 |
#必填寫的參數:
|
|
|
3629 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3630 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3631 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3632 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3633 |
#可以省略的參數:
|
|
|
3634 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3635 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url");
|
|
|
3636 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3637 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
3638 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3639 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3640 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3641 |
#$conf["canNotBeEmpty"]=array();
|
|
|
3642 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3643 |
#$conf["canBeEmpty"]=array();
|
|
|
3644 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3645 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3646 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3647 |
#$conf["skipableVariableName"]=array();
|
|
|
3648 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3649 |
#$conf["skipableVariableType"]=array();
|
|
|
3650 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3651 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3652 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3653 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3654 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3655 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3656 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3657 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3658 |
#參考資料來源:
|
|
|
3659 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3660 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3661 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3662 |
|
|
|
3663 |
#如果檢查參數失敗
|
|
|
3664 |
if($checkArguments["status"]==="false"){
|
|
|
3665 |
|
|
|
3666 |
#設置執行錯誤
|
|
|
3667 |
$result["status"]="false";
|
|
|
3668 |
|
|
|
3669 |
#設置執行錯誤訊息
|
|
|
3670 |
$result["error"]=$checkArguments;
|
|
|
3671 |
|
|
|
3672 |
#印出結果
|
|
|
3673 |
return $result;
|
|
|
3674 |
|
|
|
3675 |
}#if end
|
|
|
3676 |
|
|
|
3677 |
#如果檢查參數不通過
|
|
|
3678 |
if($checkArguments["passed"]==="false"){
|
|
|
3679 |
|
|
|
3680 |
#設置執行錯誤
|
|
|
3681 |
$result["status"]="false";
|
|
|
3682 |
|
|
|
3683 |
#設置執行錯誤訊息
|
|
|
3684 |
$result["error"]=$checkArguments;
|
|
|
3685 |
|
|
|
3686 |
#印出結果
|
|
|
3687 |
return $result;
|
|
|
3688 |
|
|
|
3689 |
}#if end
|
|
|
3690 |
|
|
|
3691 |
#函式說明:
|
|
|
3692 |
#取得指定的session數值
|
|
|
3693 |
#回傳結果:
|
|
|
3694 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
3695 |
#$result["error"],錯誤訊息.
|
|
|
3696 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
3697 |
#$result["content"],session變數的內容
|
|
|
3698 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
3699 |
#$result["function"],當前執行的函數名稱.
|
|
|
3700 |
#$result["argu"],使用的參數.
|
|
|
3701 |
#必填參數:
|
|
|
3702 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
3703 |
$conf["session::getVal"]["key"]=array("google_reCAPTCHA_pass");
|
|
|
3704 |
$getVal=session::getVal($conf["session::getVal"]);
|
|
|
3705 |
unset($conf["session::getVal"]);
|
|
|
3706 |
|
|
|
3707 |
#如果失敗
|
|
|
3708 |
if($getVal["status"]==="false"){
|
|
|
3709 |
|
|
|
3710 |
#設置執行失敗的識別
|
|
|
3711 |
$result["status"]="false";
|
|
|
3712 |
|
|
|
3713 |
#設置執行錯誤訊息
|
|
|
3714 |
$result["error"]=$getVal;
|
|
|
3715 |
|
|
|
3716 |
#回傳結果
|
|
|
3717 |
return $result;
|
|
|
3718 |
|
|
|
3719 |
}#if end
|
|
|
3720 |
|
|
|
3721 |
#如果session變數存在
|
|
|
3722 |
if($getVal["founded"]==="true"){
|
|
|
3723 |
|
|
|
3724 |
#如果已經認證完畢了
|
|
|
3725 |
if(in_array($conf["url"],$getVal["content"])){
|
|
|
3726 |
|
|
|
3727 |
#設置執行正常
|
|
|
3728 |
$result["status"]="true";
|
|
|
3729 |
|
|
|
3730 |
#設置有認證過了
|
|
|
3731 |
$result["passed"]="true";
|
|
|
3732 |
|
|
|
3733 |
#回傳結果
|
|
|
3734 |
return $result;
|
|
|
3735 |
|
|
|
3736 |
}#if end
|
|
|
3737 |
|
|
|
3738 |
}#if end
|
|
|
3739 |
|
|
|
3740 |
#設置執行正常
|
|
|
3741 |
$result["status"]="true";
|
|
|
3742 |
|
|
|
3743 |
#設置無認證過
|
|
|
3744 |
$result["passed"]="false";
|
|
|
3745 |
|
|
|
3746 |
#回傳結果
|
|
|
3747 |
return $result;
|
|
|
3748 |
|
|
|
3749 |
}#function gl_reCAPTCH_authCheck end
|
|
|
3750 |
|
|
|
3751 |
}#class authenticate end
|
|
|
3752 |
|
|
|
3753 |
?>
|