| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 3 |
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 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟 PHP session 應用相關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class session{
|
| 226 |
liveuser |
33 |
|
| 3 |
liveuser |
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#可省略參數:
|
|
|
45 |
#無.
|
|
|
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
48 |
#備註:
|
|
|
49 |
#無.
|
|
|
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
52 |
|
| 3 |
liveuser |
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
55 |
|
| 3 |
liveuser |
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
| 226 |
liveuser |
58 |
|
| 3 |
liveuser |
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
61 |
|
| 3 |
liveuser |
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
64 |
|
| 3 |
liveuser |
65 |
#回傳結果
|
|
|
66 |
return $result;
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
}#function __call end
|
| 226 |
liveuser |
69 |
|
| 3 |
liveuser |
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
80 |
#可省略參數:
|
|
|
81 |
#無.
|
|
|
82 |
#參考資料:
|
|
|
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
|
|
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
88 |
|
| 3 |
liveuser |
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
91 |
|
| 3 |
liveuser |
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
| 226 |
liveuser |
94 |
|
| 3 |
liveuser |
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
100 |
|
| 3 |
liveuser |
101 |
#回傳結果
|
|
|
102 |
return $result;
|
| 226 |
liveuser |
103 |
|
| 3 |
liveuser |
104 |
}#function __callStatic end
|
| 226 |
liveuser |
105 |
|
| 3 |
liveuser |
106 |
/*
|
|
|
107 |
#函式說明:
|
|
|
108 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
109 |
#回傳結果:
|
|
|
110 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
111 |
#$result["error"],錯誤訊息.
|
|
|
112 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
113 |
#$result["content"],取得的變數內容.
|
|
|
114 |
#$result["function"],當前執行的函數名稱.
|
|
|
115 |
#必填參數:
|
|
|
116 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
117 |
$conf["sessionVarName"]="";
|
|
|
118 |
#可省略參數:
|
|
|
119 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
120 |
#$conf["unsetSessionVar"]="true";
|
|
|
121 |
#$conf["autoCreate"],字串,是否要自動建立該 session 變數,"true"代表要,預設為"false"代表不要.
|
|
|
122 |
#$conf["autoCreate"]="true";
|
|
|
123 |
#$conf["initVal"],字串,"autoCreate"參數為"true"時,要給予的初始內容,預設為"".
|
|
|
124 |
#$conf["initVal"]="";
|
|
|
125 |
#參考資料:
|
|
|
126 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
127 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
128 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
129 |
#備註:
|
|
|
130 |
#無.
|
|
|
131 |
*/
|
|
|
132 |
public static function getSessionValue(&$conf){
|
| 226 |
liveuser |
133 |
|
| 3 |
liveuser |
134 |
#初始化要回傳的變數
|
|
|
135 |
$result=array();
|
| 226 |
liveuser |
136 |
|
| 3 |
liveuser |
137 |
#設置當前執行的函式
|
|
|
138 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
139 |
|
| 3 |
liveuser |
140 |
#如果 $conf 不為陣列
|
|
|
141 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
142 |
|
| 3 |
liveuser |
143 |
#設置執行失敗
|
|
|
144 |
$result["status"]="false";
|
| 226 |
liveuser |
145 |
|
| 3 |
liveuser |
146 |
#設置執行錯誤訊息
|
|
|
147 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
148 |
|
|
|
149 |
#如果傳入的參數為 null
|
|
|
150 |
if($conf==null){
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
#設置執行錯誤訊息
|
|
|
153 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
154 |
|
| 3 |
liveuser |
155 |
}#if end
|
|
|
156 |
|
|
|
157 |
#回傳結果
|
|
|
158 |
return $result;
|
| 226 |
liveuser |
159 |
|
| 3 |
liveuser |
160 |
}#if end
|
| 226 |
liveuser |
161 |
|
| 3 |
liveuser |
162 |
#檢查參數
|
|
|
163 |
#函式說明:
|
|
|
164 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
165 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
166 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
167 |
#$result["function"],當前執行的函式名稱.
|
|
|
168 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
169 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
170 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
171 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
172 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
173 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
174 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
175 |
#必填寫的參數:
|
|
|
176 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
177 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
178 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
179 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionVarName");
|
| 226 |
liveuser |
180 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
181 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
182 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
183 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
184 |
#可以省略的參數:
|
|
|
185 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
186 |
#$conf["canBeEmptyString"]="false";
|
|
|
187 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
188 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("unsetSessionVar","autoCreate","initVal");
|
| 226 |
liveuser |
189 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
190 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","any");
|
|
|
191 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
192 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false",null);
|
|
|
193 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
194 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("sessionArrayName","sessionArrayValue");
|
|
|
195 |
#參考資料來源:
|
|
|
196 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
197 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
198 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
199 |
|
| 3 |
liveuser |
200 |
#如果檢查參數失敗
|
|
|
201 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
202 |
|
| 3 |
liveuser |
203 |
#設置執行失敗
|
|
|
204 |
$result["status"]="false";
|
| 226 |
liveuser |
205 |
|
| 3 |
liveuser |
206 |
#設置執行錯誤訊息
|
|
|
207 |
$result["error"]=$checkArguments;
|
|
|
208 |
|
|
|
209 |
#回傳結果
|
|
|
210 |
return $result;
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
}#if end
|
| 226 |
liveuser |
213 |
|
| 3 |
liveuser |
214 |
#檢查參數不通過
|
|
|
215 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
216 |
|
| 3 |
liveuser |
217 |
#設置執行失敗
|
|
|
218 |
$result["status"]="false";
|
| 226 |
liveuser |
219 |
|
| 3 |
liveuser |
220 |
#設置執行錯誤訊息
|
|
|
221 |
$result["error"]=$checkArguments;
|
|
|
222 |
|
|
|
223 |
#回傳結果
|
|
|
224 |
return $result;
|
| 226 |
liveuser |
225 |
|
|
|
226 |
}#if end
|
|
|
227 |
|
| 3 |
liveuser |
228 |
#確認該session變數是否存在
|
|
|
229 |
if(!isset($_SESSION[$conf["sessionVarName"]])){
|
|
|
230 |
|
|
|
231 |
#設置執行正常
|
|
|
232 |
$result["status"]="true";
|
|
|
233 |
|
|
|
234 |
#設置沒有找到session變數
|
|
|
235 |
$result["founded"]="false";
|
|
|
236 |
|
|
|
237 |
#如果要自動建立該 session 變數
|
|
|
238 |
if($conf["autoCreate"]==="true"){
|
| 226 |
liveuser |
239 |
|
| 3 |
liveuser |
240 |
#函式說明:
|
|
|
241 |
#建立session變數,並指派其內容
|
|
|
242 |
#回傳結果:
|
|
|
243 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗.
|
|
|
244 |
#$result["error"],錯誤訊息陣列.
|
|
|
245 |
#$result["function"],當前執行的函數名稱.
|
|
|
246 |
#必填參數:
|
|
|
247 |
#$conf["sessionName"],字串,要建立的session變數名稱,建議可採用name1.name2.name3的格式.
|
|
|
248 |
$conf["session::create"]["sessionName"]=$conf["sessionVarName"];
|
| 226 |
liveuser |
249 |
#可省略參數:
|
|
|
250 |
|
| 3 |
liveuser |
251 |
#如果有設置 $conf["initVal"]
|
|
|
252 |
if(isset($conf["initVal"])){
|
| 226 |
liveuser |
253 |
|
| 3 |
liveuser |
254 |
#$conf["sessionValue"],字串,session變數的內容,預設為"".
|
|
|
255 |
$conf["session::create"]["sessionValue"]=$conf["initVal"];
|
| 226 |
liveuser |
256 |
|
| 3 |
liveuser |
257 |
}#if end
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
$create=session::create($conf["session::create"]);
|
|
|
260 |
unset($conf["session::create"]);
|
| 226 |
liveuser |
261 |
|
| 3 |
liveuser |
262 |
#遞迴執行
|
|
|
263 |
return session::getSessionValue($conf);
|
| 226 |
liveuser |
264 |
|
| 3 |
liveuser |
265 |
}#if end
|
|
|
266 |
|
|
|
267 |
#回傳結果
|
|
|
268 |
return $result;
|
|
|
269 |
|
|
|
270 |
}#if end
|
|
|
271 |
|
|
|
272 |
#取得session變數的內容
|
|
|
273 |
$result["content"]=$_SESSION[$conf["sessionVarName"]];
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
#設置有找到session變數
|
|
|
276 |
$result["founded"]="true";
|
|
|
277 |
|
|
|
278 |
#如果 $conf["unsetSessionVar"] 為 "true"
|
| 171 |
liveuser |
279 |
if($conf["unsetSessionVar"]==="true"){
|
| 226 |
liveuser |
280 |
|
| 3 |
liveuser |
281 |
#移除session變數的內容
|
|
|
282 |
unset($_SESSION[$conf["sessionVarName"]]);
|
| 226 |
liveuser |
283 |
|
| 3 |
liveuser |
284 |
}#if end
|
| 226 |
liveuser |
285 |
|
| 3 |
liveuser |
286 |
#設置執行正常
|
|
|
287 |
$result["status"]="true";
|
|
|
288 |
|
|
|
289 |
#回傳結果
|
| 226 |
liveuser |
290 |
return $result;
|
|
|
291 |
|
| 3 |
liveuser |
292 |
}#function getSessionValue end
|
| 226 |
liveuser |
293 |
|
| 3 |
liveuser |
294 |
/*
|
|
|
295 |
#函式說明:
|
|
|
296 |
#取得多個指定的session變數,卸除之.
|
|
|
297 |
#回傳結果:
|
|
|
298 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗。
|
|
|
299 |
#$result["error"],錯誤訊息陣列
|
|
|
300 |
#$result["function"],當前執行的函式名稱.
|
|
|
301 |
#$result["foundedAll"],是否找到所有的session變數,"true"代表找到,"false"代表沒找到.
|
|
|
302 |
#$result["founded"],每個session變數是否取得,"true"代表找到,"false"代表沒找到.
|
|
|
303 |
#$result["content"],取得的session變數內容陣列
|
|
|
304 |
#必填參數:
|
|
|
305 |
#$conf["sessionVarNameArray"],字串陣列,要取得內容的多個session變數名稱
|
|
|
306 |
$conf["sessionVarNameArray"]=array();
|
|
|
307 |
#可省略參數:
|
|
|
308 |
#$conf["keyArrayOfGotSessionValue"],字串陣列,取得的session變數是否要將其key從「0,1,2...」改成自定的「名稱1,名稱2,名稱3...」.
|
|
|
309 |
#$conf["keyArrayOfGotSessionValue"]=array();
|
|
|
310 |
#$conf["unsetSessionVars"],字串,"true"代表要卸除取值完的session變數,反之"false"爲保留session變數,預設爲"true".
|
|
|
311 |
#$conf["unsetSessionVars"]="true";
|
|
|
312 |
#參考資料:
|
|
|
313 |
#無.
|
|
|
314 |
#備註:
|
|
|
315 |
#無.
|
|
|
316 |
*/
|
|
|
317 |
public static function getMultiSessionValues(&$conf){
|
| 226 |
liveuser |
318 |
|
| 3 |
liveuser |
319 |
#初始化要回傳的變數
|
|
|
320 |
$result=array();
|
| 226 |
liveuser |
321 |
|
| 3 |
liveuser |
322 |
#設置當前執行的函式
|
|
|
323 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
324 |
|
| 3 |
liveuser |
325 |
#如果 $conf 不為陣列
|
|
|
326 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
327 |
|
| 3 |
liveuser |
328 |
#設置執行失敗
|
|
|
329 |
$result["status"]="false";
|
| 226 |
liveuser |
330 |
|
| 3 |
liveuser |
331 |
#設置執行錯誤訊息
|
|
|
332 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
333 |
|
|
|
334 |
#如果傳入的參數為 null
|
|
|
335 |
if($conf==null){
|
| 226 |
liveuser |
336 |
|
| 3 |
liveuser |
337 |
#設置執行錯誤訊息
|
|
|
338 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
339 |
|
| 3 |
liveuser |
340 |
}#if end
|
|
|
341 |
|
|
|
342 |
#回傳結果
|
|
|
343 |
return $result;
|
| 226 |
liveuser |
344 |
|
| 3 |
liveuser |
345 |
}#if end
|
| 226 |
liveuser |
346 |
|
| 3 |
liveuser |
347 |
#初始化要回傳的變數內容
|
|
|
348 |
$result["content"]=array();
|
| 226 |
liveuser |
349 |
|
| 3 |
liveuser |
350 |
#檢查參數
|
|
|
351 |
#函式說明:
|
|
|
352 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
353 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
354 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
355 |
#$result["function"],當前執行的函式名稱.
|
|
|
356 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
357 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
358 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
359 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
360 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
361 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
362 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
363 |
#必填寫的參數:
|
|
|
364 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
365 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
366 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
367 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionVarNameArray");
|
| 226 |
liveuser |
368 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
369 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
370 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
371 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
372 |
#可以省略的參數:
|
|
|
373 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
374 |
#$conf["canBeEmptyString"]="false";
|
|
|
375 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
376 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("keyArrayOfGotSessionValue","unsetSessionVars");
|
| 226 |
liveuser |
377 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
378 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
|
|
|
379 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
380 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true");
|
|
|
381 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
382 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("sessionArrayName","sessionArrayValue");
|
|
|
383 |
#參考資料來源:
|
|
|
384 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
385 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
386 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
387 |
|
| 3 |
liveuser |
388 |
#如果檢查參數失敗
|
|
|
389 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
390 |
|
| 3 |
liveuser |
391 |
#設置執行失敗
|
|
|
392 |
$result["status"]="false";
|
| 226 |
liveuser |
393 |
|
| 3 |
liveuser |
394 |
#設置執行錯誤訊息
|
|
|
395 |
$result["error"]=$checkArguments;
|
|
|
396 |
|
|
|
397 |
#回傳結果
|
|
|
398 |
return $result;
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
}#if end
|
| 226 |
liveuser |
401 |
|
| 3 |
liveuser |
402 |
#檢查參數不通過
|
|
|
403 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
404 |
|
| 3 |
liveuser |
405 |
#設置執行失敗
|
|
|
406 |
$result["status"]="false";
|
| 226 |
liveuser |
407 |
|
| 3 |
liveuser |
408 |
#設置執行錯誤訊息
|
|
|
409 |
$result["error"]=$checkArguments;
|
|
|
410 |
|
|
|
411 |
#回傳結果
|
|
|
412 |
return $result;
|
| 226 |
liveuser |
413 |
|
| 3 |
liveuser |
414 |
}#if end
|
| 226 |
liveuser |
415 |
|
| 3 |
liveuser |
416 |
#有幾個session變數要接收就執行幾次
|
|
|
417 |
for($i=0;$i<count($conf["sessionVarNameArray"]);$i++){
|
| 226 |
liveuser |
418 |
|
| 3 |
liveuser |
419 |
#函式說明:
|
|
|
420 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
421 |
#回傳結果:
|
|
|
422 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
423 |
#$result["error"],錯誤訊息
|
|
|
424 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
425 |
#$result["content"],取得的變數內容
|
|
|
426 |
#必填參數:
|
|
|
427 |
$conf["session.getSessionValue"]["sessionVarName"]=$conf["sessionVarNameArray"][$i];#要取得內容的session變數名稱
|
|
|
428 |
#可省略參數:
|
|
|
429 |
$conf["session.getSessionValue"]["unsetSessionVar"]=$conf["unsetSessionVars"];#"true"代表要卸除session變數,預設不卸除
|
|
|
430 |
#參考資料:
|
|
|
431 |
#http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
432 |
#可變變數->http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
433 |
#卸除參考的原始變數->http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
434 |
$getSessionValueResult=session::getSessionValue($conf["session.getSessionValue"]);
|
|
|
435 |
unset($conf["session.getSessionValue"]);
|
| 226 |
liveuser |
436 |
|
| 3 |
liveuser |
437 |
#debug
|
|
|
438 |
#var_dump($getSessionValueResult);
|
| 226 |
liveuser |
439 |
|
| 3 |
liveuser |
440 |
#如果取得session變數失敗
|
|
|
441 |
if($getSessionValueResult["status"]=="false"){
|
| 226 |
liveuser |
442 |
|
| 3 |
liveuser |
443 |
#設置執行不正常
|
|
|
444 |
$result["status"]="false";
|
| 226 |
liveuser |
445 |
|
| 3 |
liveuser |
446 |
#設置執行錯誤的訊息
|
|
|
447 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
448 |
|
| 3 |
liveuser |
449 |
#回傳結果
|
|
|
450 |
return $result;
|
| 226 |
liveuser |
451 |
|
| 3 |
liveuser |
452 |
}#if end
|
| 226 |
liveuser |
453 |
|
| 3 |
liveuser |
454 |
#如果該session變數不存在
|
|
|
455 |
if($getSessionValueResult["founded"]=="false"){
|
| 226 |
liveuser |
456 |
|
| 3 |
liveuser |
457 |
#設置該session變數不存在
|
|
|
458 |
$result["founded"][$i]="false";
|
| 226 |
liveuser |
459 |
|
| 3 |
liveuser |
460 |
}#if end
|
| 226 |
liveuser |
461 |
|
| 3 |
liveuser |
462 |
#反之session變數存在
|
|
|
463 |
else{
|
| 226 |
liveuser |
464 |
|
| 3 |
liveuser |
465 |
#設置該session變數存在
|
|
|
466 |
$result["founded"][$i]="true";
|
| 226 |
liveuser |
467 |
|
| 3 |
liveuser |
468 |
#取得session變數的內容
|
|
|
469 |
$result["content"][$i]=$getSessionValueResult["content"];
|
| 226 |
liveuser |
470 |
|
| 3 |
liveuser |
471 |
}#else end
|
| 226 |
liveuser |
472 |
|
| 3 |
liveuser |
473 |
}#for end
|
| 226 |
liveuser |
474 |
|
| 3 |
liveuser |
475 |
#如果 $conf["keyArrayOfGotSessionValue"] 有設置
|
|
|
476 |
if(isset($conf["keyArrayOfGotSessionValue"])){
|
| 226 |
liveuser |
477 |
|
| 3 |
liveuser |
478 |
#如果 $conf["keyArrayOfGotSessionValue"] 與 $conf["sessionVarNameArray"] 的元素數量相等
|
|
|
479 |
if(count($conf["keyArrayOfGotSessionValue"])==count($conf["sessionVarNameArray"])){
|
| 226 |
liveuser |
480 |
|
| 3 |
liveuser |
481 |
#$conf["keyArrayOfGotSessionValue"]有幾個元素就執行幾次
|
|
|
482 |
for($i=0;$i<count($conf["keyArrayOfGotSessionValue"]);$i++){
|
| 226 |
liveuser |
483 |
|
| 3 |
liveuser |
484 |
#給與新key
|
|
|
485 |
$result["founded"][$conf["keyArrayOfGotSessionValue"][$i]]=$result["founded"][$i];
|
| 226 |
liveuser |
486 |
|
| 3 |
liveuser |
487 |
#如果存在session變數
|
|
|
488 |
if(isset($result["content"][$i])){
|
| 226 |
liveuser |
489 |
|
| 3 |
liveuser |
490 |
#給與新key
|
|
|
491 |
$result["content"][$conf["keyArrayOfGotSessionValue"][$i]]=$result["content"][$i];
|
| 226 |
liveuser |
492 |
|
| 3 |
liveuser |
493 |
#移除舊key的變數
|
|
|
494 |
unset($result["content"][$i]);
|
| 226 |
liveuser |
495 |
|
| 3 |
liveuser |
496 |
}#if end
|
| 226 |
liveuser |
497 |
|
| 3 |
liveuser |
498 |
#移除舊key的變數
|
|
|
499 |
unset($result["founded"][$i]);
|
| 226 |
liveuser |
500 |
|
|
|
501 |
}#for end
|
|
|
502 |
|
| 3 |
liveuser |
503 |
}#if end
|
| 226 |
liveuser |
504 |
|
| 3 |
liveuser |
505 |
#反之 $conf["keyArrayOfGotSessionValue"] 與 $conf["sessionVarNameArray"] 的元素數量不相等
|
|
|
506 |
else{
|
| 226 |
liveuser |
507 |
|
| 3 |
liveuser |
508 |
#設置執行不正常
|
|
|
509 |
$result["status"]="false";
|
| 226 |
liveuser |
510 |
|
| 3 |
liveuser |
511 |
#設置執行錯誤的訊息
|
|
|
512 |
$result["error"][]="\$conf[\"keyArrayOfGotSessionValue\"] 與 \$conf[\"sessionVarNameArray\"] 的元素數量不相等";
|
| 226 |
liveuser |
513 |
|
| 3 |
liveuser |
514 |
#回傳結果
|
|
|
515 |
return $result;
|
| 226 |
liveuser |
516 |
|
| 3 |
liveuser |
517 |
}#else end
|
| 226 |
liveuser |
518 |
|
| 3 |
liveuser |
519 |
}#if end
|
| 226 |
liveuser |
520 |
|
| 3 |
liveuser |
521 |
#如果有一個session變數沒找到
|
|
|
522 |
foreach($result["founded"] as $value){
|
| 226 |
liveuser |
523 |
|
| 3 |
liveuser |
524 |
#如果等於 "false"
|
|
|
525 |
if($value=="false"){
|
| 226 |
liveuser |
526 |
|
| 3 |
liveuser |
527 |
#設置沒有每個session變數都抓到
|
|
|
528 |
$result["foundedAll"]="false";
|
| 226 |
liveuser |
529 |
|
| 3 |
liveuser |
530 |
#跳出foreach
|
|
|
531 |
break;
|
| 226 |
liveuser |
532 |
|
| 3 |
liveuser |
533 |
}#if end
|
| 226 |
liveuser |
534 |
|
| 3 |
liveuser |
535 |
}#foreach end
|
| 226 |
liveuser |
536 |
|
| 3 |
liveuser |
537 |
#如果 $result["foundedAll"] 沒有設置
|
|
|
538 |
if(!isset($result["foundedAll"])){
|
| 226 |
liveuser |
539 |
|
| 3 |
liveuser |
540 |
#設爲 "true"
|
|
|
541 |
$result["foundedAll"]="true";
|
| 226 |
liveuser |
542 |
|
| 3 |
liveuser |
543 |
}#if end
|
| 226 |
liveuser |
544 |
|
| 3 |
liveuser |
545 |
#設置執行結果爲正常
|
|
|
546 |
$result["status"]="true";
|
| 226 |
liveuser |
547 |
|
| 3 |
liveuser |
548 |
#回傳結果
|
|
|
549 |
return $result;
|
| 226 |
liveuser |
550 |
|
| 3 |
liveuser |
551 |
}#funtion getMultiSessionValues end
|
| 226 |
liveuser |
552 |
|
| 3 |
liveuser |
553 |
/*
|
|
|
554 |
#函式說明:
|
|
|
555 |
#建立session變數,並指派其內容
|
|
|
556 |
#回傳結果:
|
|
|
557 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗.
|
|
|
558 |
#$result["error"],錯誤訊息陣列.
|
|
|
559 |
#$result["argu"],使用的參數.
|
|
|
560 |
#$result["function"],當前執行的函數名稱.
|
|
|
561 |
#必填參數:
|
|
|
562 |
#$conf["sessionName"],字串,要建立的session變數名稱,建議可採用name1.name2.name3的格式.
|
|
|
563 |
$conf["sessionName"]="";
|
| 226 |
liveuser |
564 |
#可省略參數:
|
| 3 |
liveuser |
565 |
#$conf["sessionValue"],字串,session變數的內容,預設為"".
|
|
|
566 |
#$conf["sessionValue"]="";
|
|
|
567 |
#參考資料:
|
|
|
568 |
#無.
|
|
|
569 |
#備註:
|
|
|
570 |
#無.
|
|
|
571 |
*/
|
|
|
572 |
public static function create(&$conf){
|
| 226 |
liveuser |
573 |
|
| 3 |
liveuser |
574 |
#初始化要回傳的變數
|
|
|
575 |
$result=array();
|
| 226 |
liveuser |
576 |
|
| 3 |
liveuser |
577 |
#儲存使用的參數
|
|
|
578 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
579 |
|
| 3 |
liveuser |
580 |
#記錄當前執行的函數名稱
|
|
|
581 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
582 |
|
| 3 |
liveuser |
583 |
#如果 $conf 不為陣列
|
|
|
584 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
585 |
|
| 3 |
liveuser |
586 |
#設置執行失敗
|
|
|
587 |
$result["status"]="false";
|
| 226 |
liveuser |
588 |
|
| 3 |
liveuser |
589 |
#設置執行錯誤訊息
|
|
|
590 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
591 |
|
|
|
592 |
#如果傳入的參數為 null
|
|
|
593 |
if($conf==null){
|
| 226 |
liveuser |
594 |
|
| 3 |
liveuser |
595 |
#設置執行錯誤訊息
|
|
|
596 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
597 |
|
| 3 |
liveuser |
598 |
}#if end
|
|
|
599 |
|
|
|
600 |
#回傳結果
|
|
|
601 |
return $result;
|
| 226 |
liveuser |
602 |
|
| 3 |
liveuser |
603 |
}#if end
|
| 226 |
liveuser |
604 |
|
| 3 |
liveuser |
605 |
#檢查參數
|
|
|
606 |
#函式說明:
|
|
|
607 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
608 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
609 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
610 |
#$result["function"],當前執行的函式名稱.
|
|
|
611 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
612 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
613 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
614 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
615 |
#必填寫的參數:
|
|
|
616 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
617 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
618 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
619 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionName");
|
| 226 |
liveuser |
620 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
621 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
622 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
623 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
624 |
#可以省略的參數:
|
|
|
625 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
626 |
#$conf["canBeEmptyString"]="false";
|
|
|
627 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
628 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sessionValue");
|
| 226 |
liveuser |
629 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
630 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array();
|
|
|
631 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
632 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
633 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
634 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
635 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
636 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
637 |
|
| 3 |
liveuser |
638 |
#如果檢查失敗
|
|
|
639 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
640 |
|
| 3 |
liveuser |
641 |
#設置執行錯誤的識別
|
|
|
642 |
$result["status"]="false";
|
| 226 |
liveuser |
643 |
|
| 3 |
liveuser |
644 |
#設置執行失敗的錯誤訊息
|
|
|
645 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
646 |
|
| 3 |
liveuser |
647 |
#回傳結果
|
|
|
648 |
return $result;
|
| 226 |
liveuser |
649 |
|
| 3 |
liveuser |
650 |
}#if end
|
| 226 |
liveuser |
651 |
|
| 3 |
liveuser |
652 |
#如果檢查不通過
|
|
|
653 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
654 |
|
| 3 |
liveuser |
655 |
#設置執行錯誤的識別
|
|
|
656 |
$result["status"]="false";
|
| 226 |
liveuser |
657 |
|
| 3 |
liveuser |
658 |
#設置執行失敗的錯誤訊息
|
|
|
659 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
660 |
|
| 3 |
liveuser |
661 |
#回傳結果
|
|
|
662 |
return $result;
|
| 226 |
liveuser |
663 |
|
| 3 |
liveuser |
664 |
}#if end
|
| 226 |
liveuser |
665 |
|
| 3 |
liveuser |
666 |
#建立session變數,並指派其直
|
|
|
667 |
$_SESSION[$conf["sessionName"]]=$conf["sessionValue"];
|
| 226 |
liveuser |
668 |
|
| 3 |
liveuser |
669 |
#設置執行成功的辨識訊息
|
|
|
670 |
$result["status"]="true";
|
| 226 |
liveuser |
671 |
|
| 3 |
liveuser |
672 |
#回傳結果
|
|
|
673 |
return $result;
|
| 226 |
liveuser |
674 |
|
| 3 |
liveuser |
675 |
}#function create end
|
| 226 |
liveuser |
676 |
|
| 3 |
liveuser |
677 |
/*
|
|
|
678 |
#函式說明:
|
|
|
679 |
#記錄當前訪問的頁面,並且保存上一個訪問的頁面.
|
|
|
680 |
#回傳結果:
|
|
|
681 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
682 |
#$result["error"],錯誤訊息.
|
|
|
683 |
#$result["function"],當前執行的函數名稱.
|
|
|
684 |
#$result["nowPosition"],現在瀏覽的路徑.
|
|
|
685 |
#$result["prePosition"],上一個瀏覽的路徑.
|
|
|
686 |
#$result["phpNowViewed"],當前瀏覽的檔案名稱.
|
|
|
687 |
#$resutl["phpPreViewed"],上一個瀏覽的檔案名稱.
|
|
|
688 |
#必填參數:
|
|
|
689 |
#無.
|
|
|
690 |
#可省略參數:
|
|
|
691 |
#無.
|
|
|
692 |
#參考資料:
|
|
|
693 |
#無.
|
|
|
694 |
#備註:
|
|
|
695 |
#當一個頁面有多個頁框時,會導致當前瀏覽的頁面與上一個瀏覽的頁面被複寫.
|
|
|
696 |
*/
|
|
|
697 |
public static function getPreAndNowPosition(){
|
|
|
698 |
|
|
|
699 |
#初始化要回傳的變數
|
|
|
700 |
$result=array();
|
| 226 |
liveuser |
701 |
|
| 3 |
liveuser |
702 |
#設置當前執行的函式
|
|
|
703 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
704 |
|
| 3 |
liveuser |
705 |
#如果 $conf 不為陣列
|
|
|
706 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
707 |
|
| 3 |
liveuser |
708 |
#設置執行失敗
|
|
|
709 |
$result["status"]="false";
|
| 226 |
liveuser |
710 |
|
| 3 |
liveuser |
711 |
#設置執行錯誤訊息
|
|
|
712 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
713 |
|
|
|
714 |
#如果傳入的參數為 null
|
|
|
715 |
if($conf==null){
|
| 226 |
liveuser |
716 |
|
| 3 |
liveuser |
717 |
#設置執行錯誤訊息
|
|
|
718 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
719 |
|
| 3 |
liveuser |
720 |
}#if end
|
|
|
721 |
|
|
|
722 |
#回傳結果
|
|
|
723 |
return $result;
|
| 226 |
liveuser |
724 |
|
| 3 |
liveuser |
725 |
}#if end
|
|
|
726 |
|
|
|
727 |
#設置當前執行的函式
|
|
|
728 |
$result["function"]=__FUNCTION__;
|
|
|
729 |
|
|
|
730 |
#如果 $_SESSION["session"]["getPreAndNowPosition"]["prePlace"] 不存在
|
|
|
731 |
if(!isset($_SESSION["session"]["getPreAndNowPosition"]["prePlace"])){
|
|
|
732 |
|
|
|
733 |
#將之設為 ""
|
|
|
734 |
$_SESSION["session"]["getPreAndNowPosition"]["prePlace"]="";
|
| 226 |
liveuser |
735 |
|
| 3 |
liveuser |
736 |
}#if end
|
| 226 |
liveuser |
737 |
|
| 3 |
liveuser |
738 |
#如果 $_SESSION["session"]["getPreAndNowPosition"]["nowPlace"] 存在
|
|
|
739 |
if(isset($_SESSION["session"]["getPreAndNowPosition"]["nowPlace"])){
|
| 226 |
liveuser |
740 |
|
| 3 |
liveuser |
741 |
#設置 $_SESSION["session"]["getPreAndNowPosition"]["prePlace"] 為 $_SESSION["session"]["getPreAndNowPosition"]["nowPlace"]
|
|
|
742 |
$_SESSION["session"]["getPreAndNowPosition"]["prePlace"]=$_SESSION["session"]["getPreAndNowPosition"]["nowPlace"];
|
| 226 |
liveuser |
743 |
|
| 3 |
liveuser |
744 |
#設置 $_SESSION["session"]["getPreAndNowPosition"]["nowPlace"] 為 $_SERVER["PHP_SELF"]
|
|
|
745 |
$_SESSION["session"]["getPreAndNowPosition"]["nowPlace"]=$_SERVER["PHP_SELF"];
|
| 226 |
liveuser |
746 |
|
| 3 |
liveuser |
747 |
}#if end
|
| 226 |
liveuser |
748 |
|
| 3 |
liveuser |
749 |
#反之 $_SESSION["session"]["getPreAndNowPosition"]["nowPlace"] 沒有設置
|
|
|
750 |
else{
|
| 226 |
liveuser |
751 |
|
| 3 |
liveuser |
752 |
#將 $_SESSION["session"]["getPreAndNowPosition"]["nowPlace"] 設為 $_SERVER["PHP_SELF"]
|
|
|
753 |
$_SESSION["session"]["getPreAndNowPosition"]["nowPlace"]=$_SERVER["PHP_SELF"];
|
| 226 |
liveuser |
754 |
|
| 3 |
liveuser |
755 |
}#else end
|
| 226 |
liveuser |
756 |
|
| 3 |
liveuser |
757 |
#記錄要回傳的內容
|
| 226 |
liveuser |
758 |
|
| 3 |
liveuser |
759 |
#記錄當前瀏覽的目錄
|
|
|
760 |
#函式說明:
|
|
|
761 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
762 |
#回傳的參數:
|
|
|
763 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
764 |
#$result["error"],錯誤訊息陣列
|
|
|
765 |
#$result["function"],當前執行的函數名稱.
|
|
|
766 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
767 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
768 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
769 |
#必填參數:
|
|
|
770 |
$conf["stringIn"]=$_SESSION["session"]["getPreAndNowPosition"]["nowPlace"];#要處理的字串。
|
|
|
771 |
$conf["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
772 |
$processedStr=stringProcess::spiltString($conf);
|
|
|
773 |
unset($conf);
|
| 226 |
liveuser |
774 |
|
| 3 |
liveuser |
775 |
#如果處理字串失敗
|
|
|
776 |
if($processedStr["status"]=="false"){
|
| 226 |
liveuser |
777 |
|
| 3 |
liveuser |
778 |
#設置錯誤識別
|
|
|
779 |
$result["status"]="false";
|
| 226 |
liveuser |
780 |
|
| 3 |
liveuser |
781 |
#設置錯誤訊息
|
|
|
782 |
$result["error"]=$processedStr;
|
| 226 |
liveuser |
783 |
|
| 3 |
liveuser |
784 |
#回傳結果
|
|
|
785 |
return $result;
|
| 226 |
liveuser |
786 |
|
| 3 |
liveuser |
787 |
}#if end
|
| 226 |
liveuser |
788 |
|
| 3 |
liveuser |
789 |
#初始化 $result["phpNowViewed"] 為 ""
|
|
|
790 |
$result["nowPosition"]="";
|
| 226 |
liveuser |
791 |
|
| 3 |
liveuser |
792 |
#針對 $processedStr["dataCounts"] 的數字來合併目錄
|
|
|
793 |
for($i=0;$i<$processedStr["dataCounts"]-1;$i++){
|
| 226 |
liveuser |
794 |
|
| 3 |
liveuser |
795 |
#合併目錄
|
|
|
796 |
$result["nowPosition"]=$result["nowPosition"].$processedStr["dataArray"][$i]."/";
|
| 226 |
liveuser |
797 |
|
| 3 |
liveuser |
798 |
}#for end
|
| 226 |
liveuser |
799 |
|
| 3 |
liveuser |
800 |
#記錄上一個瀏覽的目錄
|
|
|
801 |
#函式說明:
|
|
|
802 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
803 |
#回傳的參數:
|
|
|
804 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
805 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
806 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
807 |
#必填參數:
|
|
|
808 |
$conf["stringIn"]=$_SESSION["session"]["getPreAndNowPosition"]["prePlace"];#要處理的字串。
|
|
|
809 |
$conf["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
810 |
$processedStr=stringProcess::spiltString($conf);
|
|
|
811 |
unset($conf);
|
| 226 |
liveuser |
812 |
|
| 3 |
liveuser |
813 |
#如果處理字串失敗
|
|
|
814 |
if($processedStr["status"]=="false"){
|
| 226 |
liveuser |
815 |
|
| 3 |
liveuser |
816 |
#設置錯誤識別
|
|
|
817 |
$result["status"]="false";
|
| 226 |
liveuser |
818 |
|
| 3 |
liveuser |
819 |
#設置錯誤訊息
|
|
|
820 |
$result["error"]=$processedStr;
|
| 226 |
liveuser |
821 |
|
| 3 |
liveuser |
822 |
#回傳結果
|
|
|
823 |
return $result;
|
| 226 |
liveuser |
824 |
|
| 3 |
liveuser |
825 |
}#if end
|
| 226 |
liveuser |
826 |
|
| 3 |
liveuser |
827 |
#初始化 $result["prePosition"] 為 ""
|
|
|
828 |
$result["prePosition"]="";
|
| 226 |
liveuser |
829 |
|
| 3 |
liveuser |
830 |
#針對 $processedStr["dataCounts"] 的數字來合併目錄
|
|
|
831 |
for($i=0;$i<$processedStr["dataCounts"]-1;$i++){
|
| 226 |
liveuser |
832 |
|
| 3 |
liveuser |
833 |
#合併目錄
|
|
|
834 |
$result["prePosition"]=$result["prePosition"].$processedStr["dataArray"][$i]."/";
|
| 226 |
liveuser |
835 |
|
| 3 |
liveuser |
836 |
}#for end
|
| 226 |
liveuser |
837 |
|
| 3 |
liveuser |
838 |
#記錄當前瀏覽的檔案名稱
|
|
|
839 |
$result["phpNowViewed"]=basename($_SESSION["session"]["getPreAndNowPosition"]["nowPlace"]);
|
| 226 |
liveuser |
840 |
|
| 3 |
liveuser |
841 |
#記錄上一筆瀏覽的檔案名稱
|
|
|
842 |
$result["phpPreViewed"]=basename($_SESSION["session"]["getPreAndNowPosition"]["prePlace"]);
|
| 226 |
liveuser |
843 |
|
| 3 |
liveuser |
844 |
#設置執行正常
|
|
|
845 |
$result["status"]="true";
|
| 226 |
liveuser |
846 |
|
| 3 |
liveuser |
847 |
#回傳結果
|
|
|
848 |
return $result;
|
| 226 |
liveuser |
849 |
|
| 3 |
liveuser |
850 |
}#function getPreAndNowPosition end
|
| 226 |
liveuser |
851 |
|
| 3 |
liveuser |
852 |
/*
|
|
|
853 |
#函式說明:
|
|
|
854 |
#建立多個session變數
|
|
|
855 |
#回傳結果:
|
|
|
856 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗.
|
|
|
857 |
#$reuslt["function"],當前執行的函數.
|
|
|
858 |
#$result["error"],錯誤訊息陣列.
|
|
|
859 |
#必填參數:
|
|
|
860 |
#$conf["sessionArrayName"],字串陣列,要建立的session陣列變數名稱,建議可採用name1.name2.name3的格式。
|
|
|
861 |
$conf["sessionArrayName"]=array("");
|
|
|
862 |
#$conf["sessionArrayValue"],字串陣列,session變數的內容要存放什麼呢?
|
|
|
863 |
$conf["sessionArrayValue"]=array("");
|
|
|
864 |
#可省略參數:
|
|
|
865 |
#無.
|
|
|
866 |
#參考資料:
|
|
|
867 |
#無.
|
|
|
868 |
#備註:
|
|
|
869 |
#無.
|
|
|
870 |
*/
|
|
|
871 |
public static function createMulti(&$conf){
|
| 226 |
liveuser |
872 |
|
| 3 |
liveuser |
873 |
#初始化要回傳的變數
|
|
|
874 |
$result=array();
|
| 226 |
liveuser |
875 |
|
| 3 |
liveuser |
876 |
#設置當前執行的函式
|
|
|
877 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
878 |
|
| 3 |
liveuser |
879 |
#如果 $conf 不為陣列
|
| 171 |
liveuser |
880 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
881 |
|
| 3 |
liveuser |
882 |
#設置執行失敗
|
|
|
883 |
$result["status"]="false";
|
| 226 |
liveuser |
884 |
|
| 3 |
liveuser |
885 |
#設置執行錯誤訊息
|
|
|
886 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
887 |
|
|
|
888 |
#如果傳入的參數為 null
|
| 171 |
liveuser |
889 |
if($conf===null){
|
| 226 |
liveuser |
890 |
|
| 3 |
liveuser |
891 |
#設置執行錯誤訊息
|
|
|
892 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
893 |
|
| 3 |
liveuser |
894 |
}#if end
|
|
|
895 |
|
|
|
896 |
#回傳結果
|
|
|
897 |
return $result;
|
| 226 |
liveuser |
898 |
|
| 3 |
liveuser |
899 |
}#if end
|
| 226 |
liveuser |
900 |
|
| 3 |
liveuser |
901 |
#檢查參數
|
|
|
902 |
#函式說明:
|
|
|
903 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
904 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
905 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
906 |
#$result["function"],當前執行的函式名稱.
|
|
|
907 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
908 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
909 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
910 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
911 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
912 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
913 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
914 |
#必填寫的參數:
|
|
|
915 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
916 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
917 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
918 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionArrayName","sessionArrayValue");
|
| 226 |
liveuser |
919 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
920 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array");
|
|
|
921 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
922 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
923 |
#可以省略的參數:
|
|
|
924 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
925 |
#$conf["canBeEmptyString"]="false";
|
|
|
926 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
927 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array();
|
| 226 |
liveuser |
928 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
929 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array();
|
|
|
930 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
931 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
932 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
933 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("sessionArrayName","sessionArrayValue");
|
|
|
934 |
#參考資料來源:
|
|
|
935 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
936 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
937 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
938 |
|
| 3 |
liveuser |
939 |
#如果檢查參數失敗
|
|
|
940 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
941 |
|
| 3 |
liveuser |
942 |
#設置執行失敗
|
|
|
943 |
$result["status"]="false";
|
| 226 |
liveuser |
944 |
|
| 3 |
liveuser |
945 |
#設置執行錯誤訊息
|
|
|
946 |
$result["error"]=$checkArguments;
|
|
|
947 |
|
|
|
948 |
#回傳結果
|
|
|
949 |
return $result;
|
| 226 |
liveuser |
950 |
|
| 3 |
liveuser |
951 |
}#if end
|
| 226 |
liveuser |
952 |
|
| 3 |
liveuser |
953 |
#檢查參數不通過
|
|
|
954 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
955 |
|
| 3 |
liveuser |
956 |
#設置執行失敗
|
|
|
957 |
$result["status"]="false";
|
| 226 |
liveuser |
958 |
|
| 3 |
liveuser |
959 |
#設置執行錯誤訊息
|
|
|
960 |
$result["error"]=$checkArguments;
|
|
|
961 |
|
|
|
962 |
#回傳結果
|
|
|
963 |
return $result;
|
| 226 |
liveuser |
964 |
|
| 3 |
liveuser |
965 |
}#if end
|
| 226 |
liveuser |
966 |
|
| 3 |
liveuser |
967 |
#執行迴圈 count($conf["sessionArrayName"]) 次
|
|
|
968 |
for($i=0;$i<count($conf["sessionArrayName"]);$i++){
|
| 226 |
liveuser |
969 |
|
| 3 |
liveuser |
970 |
#函式說明:
|
|
|
971 |
#建立session變數,並指派其內容
|
|
|
972 |
#回傳結果:
|
|
|
973 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗。
|
|
|
974 |
#$result["error"],錯誤訊息陣列
|
|
|
975 |
#必填參數:
|
|
|
976 |
$conf["session.create"]["sessionName"]=$conf["sessionArrayName"][$i];#要建立的session變數名稱,建議可採用name1.name2.name3的格式。
|
| 226 |
liveuser |
977 |
#可省略參數:
|
|
|
978 |
$conf["session.create"]["sessionValue"]=$conf["sessionArrayValue"][$i];#session變數的內容要存放什麼呢?
|
| 3 |
liveuser |
979 |
$sessionCreateResult=session::create($conf["session.create"]);
|
|
|
980 |
unset($conf["session.create"]);
|
| 226 |
liveuser |
981 |
|
| 3 |
liveuser |
982 |
#如果 建立 session 變數失敗
|
|
|
983 |
if($sessionCreateResult["status"]=="false"){
|
| 226 |
liveuser |
984 |
|
| 3 |
liveuser |
985 |
#設置執行錯誤的識別
|
|
|
986 |
$result["status"]="false";
|
| 226 |
liveuser |
987 |
|
| 3 |
liveuser |
988 |
#設置執行失敗的錯誤訊息
|
|
|
989 |
$result["error"]=$sessionCreateResult;
|
| 226 |
liveuser |
990 |
|
| 3 |
liveuser |
991 |
#回傳結果
|
|
|
992 |
return $result;
|
| 226 |
liveuser |
993 |
|
| 3 |
liveuser |
994 |
}#if end
|
| 226 |
liveuser |
995 |
|
| 3 |
liveuser |
996 |
}#for end
|
| 226 |
liveuser |
997 |
|
| 3 |
liveuser |
998 |
#執行到這邊代表執行成功
|
|
|
999 |
$result["status"]="true";
|
| 226 |
liveuser |
1000 |
|
| 3 |
liveuser |
1001 |
#設置執行正常的識別
|
|
|
1002 |
$result["status"]="true";
|
| 226 |
liveuser |
1003 |
|
| 3 |
liveuser |
1004 |
#回傳結果
|
|
|
1005 |
return $result;
|
| 226 |
liveuser |
1006 |
|
| 3 |
liveuser |
1007 |
}#function createMulti end
|
| 226 |
liveuser |
1008 |
|
| 3 |
liveuser |
1009 |
/*
|
|
|
1010 |
#函式說明:
|
| 226 |
liveuser |
1011 |
#接收post表單變數後另存成session變數
|
| 3 |
liveuser |
1012 |
#回傳結果:
|
|
|
1013 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1014 |
#$result["errot"],錯誤訊息陣列.
|
|
|
1015 |
#$result["function"],當前的函數名稱.
|
|
|
1016 |
#必填參數:
|
|
|
1017 |
#$conf["checkedVarName"],字串陣列,要接收的表單變數名稱陣列,如果有缺就代表不通過.
|
|
|
1018 |
$conf["checkedVarName"]=array();
|
|
|
1019 |
#可省略參數:
|
|
|
1020 |
#$conf["limitPrePage"],字串陣列,為前一頁的名稱須為陣列元素之一,不滿足則代表不合法,因此要轉址。
|
|
|
1021 |
#$conf["limitPrePage"]=array();
|
|
|
1022 |
#$conf["transferLocation"],變數來的途徑不合法時要轉址到的地方,預設爲資安素養網"https://isafe.moe.edu.tw/
|
|
|
1023 |
#$conf["transferLocation"]="";
|
|
|
1024 |
#$conf["sessionArrayName"],字串陣列,各個表單變數要轉存成session變數時的key為何.
|
|
|
1025 |
#$conf["sessionArrayName"]=array();
|
|
|
1026 |
#參考資料:
|
|
|
1027 |
#無.
|
|
|
1028 |
#備註:
|
|
|
1029 |
#無.
|
|
|
1030 |
*/
|
|
|
1031 |
public static function formVarToSession(&$conf){
|
| 226 |
liveuser |
1032 |
|
| 3 |
liveuser |
1033 |
#初始化要回傳的變數
|
|
|
1034 |
$result=array();
|
| 226 |
liveuser |
1035 |
|
| 3 |
liveuser |
1036 |
#設置當前執行的函式
|
|
|
1037 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1038 |
|
| 3 |
liveuser |
1039 |
#如果 $conf 不為陣列
|
|
|
1040 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1041 |
|
| 3 |
liveuser |
1042 |
#設置執行失敗
|
|
|
1043 |
$result["status"]="false";
|
| 226 |
liveuser |
1044 |
|
| 3 |
liveuser |
1045 |
#設置執行錯誤訊息
|
|
|
1046 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1047 |
|
|
|
1048 |
#如果傳入的參數為 null
|
|
|
1049 |
if($conf==null){
|
| 226 |
liveuser |
1050 |
|
| 3 |
liveuser |
1051 |
#設置執行錯誤訊息
|
|
|
1052 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1053 |
|
| 3 |
liveuser |
1054 |
}#if end
|
|
|
1055 |
|
|
|
1056 |
#回傳結果
|
|
|
1057 |
return $result;
|
| 226 |
liveuser |
1058 |
|
| 3 |
liveuser |
1059 |
}#if end
|
| 226 |
liveuser |
1060 |
|
| 3 |
liveuser |
1061 |
#檢查參數
|
|
|
1062 |
#函式說明:
|
|
|
1063 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1064 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1065 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1066 |
#$result["function"],當前執行的函式名稱.
|
|
|
1067 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1068 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1069 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1070 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1071 |
#必填寫的參數:
|
|
|
1072 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1073 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1074 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1075 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("checkedVarName");
|
| 226 |
liveuser |
1076 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1077 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
1078 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1079 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
1080 |
#可以省略的參數:
|
|
|
1081 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1082 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1083 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1084 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("limitPrePage","transferLocation","sessionArrayName");
|
| 226 |
liveuser |
1085 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1086 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","string","array");
|
|
|
1087 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1088 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(null,null,"\$conf[\"checkedVarName\"]");
|
|
|
1089 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1090 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1091 |
|
| 3 |
liveuser |
1092 |
#如果檢查失敗
|
|
|
1093 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1094 |
|
| 3 |
liveuser |
1095 |
#設置執行不正常
|
|
|
1096 |
$result["status"]="false";
|
| 226 |
liveuser |
1097 |
|
| 3 |
liveuser |
1098 |
#設置錯誤訊息
|
|
|
1099 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1100 |
|
| 3 |
liveuser |
1101 |
#回傳結果
|
|
|
1102 |
return $result;
|
| 226 |
liveuser |
1103 |
|
| 3 |
liveuser |
1104 |
}#if end
|
| 226 |
liveuser |
1105 |
|
| 3 |
liveuser |
1106 |
#函式說明:
|
|
|
1107 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數
|
|
|
1108 |
#回傳結果:
|
|
|
1109 |
#$result["status"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
|
|
|
1110 |
#$result["error"],錯誤訊息.
|
|
|
1111 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
1112 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
1113 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
1114 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
1115 |
#$result["inputDataCount"],總共接收到幾個元素.
|
|
|
1116 |
#必填參數:
|
|
|
1117 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
1118 |
$conf["form.responseMultiInputDataSecurityEnhance"]["method"]="post";
|
|
|
1119 |
#可省略參數:
|
|
|
1120 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
1121 |
#$conf["allowGet"]="true";
|
| 226 |
liveuser |
1122 |
|
| 3 |
liveuser |
1123 |
#如果有設定 $conf["limitPrePage"]
|
|
|
1124 |
if(isset($conf["limitPrePage"])){
|
| 226 |
liveuser |
1125 |
|
| 3 |
liveuser |
1126 |
#$conf["form.responseMultiInputDataSecurityEnhance"]["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
1127 |
$conf["form.responseMultiInputDataSecurityEnhance"]["limitPrePage"]=$conf["limitPrePage"];
|
| 226 |
liveuser |
1128 |
|
| 3 |
liveuser |
1129 |
}#if end
|
| 226 |
liveuser |
1130 |
|
| 3 |
liveuser |
1131 |
#如果 $conf["transferLocation"] 有設定
|
|
|
1132 |
if(isset($conf["transferLocation"])){
|
| 226 |
liveuser |
1133 |
|
| 3 |
liveuser |
1134 |
#$conf["form.responseMultiInputDataSecurityEnhance"]["transferLocation"],字串,遇到get傳值的時候要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
1135 |
$conf["form.responseMultiInputDataSecurityEnhance"]["transferLocation"]=$conf["transferLocation"];
|
| 226 |
liveuser |
1136 |
|
| 3 |
liveuser |
1137 |
}#if end
|
| 226 |
liveuser |
1138 |
|
| 3 |
liveuser |
1139 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
1140 |
#$conf["ignore"]=array();
|
|
|
1141 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
1142 |
#$conf["correctCharacter"]="false";
|
| 226 |
liveuser |
1143 |
|
| 3 |
liveuser |
1144 |
#如果 $conf["checkedVarName"] 有設定
|
|
|
1145 |
if(isset($conf["checkedVarName"])){
|
| 226 |
liveuser |
1146 |
|
| 3 |
liveuser |
1147 |
#$conf["form.responseMultiInputDataSecurityEnhance"]["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
1148 |
$conf["form.responseMultiInputDataSecurityEnhance"]["checkedVarName"]=$conf["checkedVarName"];
|
| 226 |
liveuser |
1149 |
|
| 3 |
liveuser |
1150 |
}#if end
|
| 226 |
liveuser |
1151 |
|
| 3 |
liveuser |
1152 |
#參考資料來源:
|
|
|
1153 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
1154 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
1155 |
#備註:
|
|
|
1156 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
1157 |
$receivedVar=form::responseMultiInputDataSecurityEnhance($conf["form.responseMultiInputDataSecurityEnhance"]);
|
|
|
1158 |
unset($conf["form.responseMultiInputDataSecurityEnhance"]);
|
| 226 |
liveuser |
1159 |
|
| 3 |
liveuser |
1160 |
#如果接受變數失敗
|
|
|
1161 |
if($receivedVar["status"]=="false"){
|
| 226 |
liveuser |
1162 |
|
| 3 |
liveuser |
1163 |
#設置執行不正常
|
|
|
1164 |
$result["status"]="false";
|
| 226 |
liveuser |
1165 |
|
| 3 |
liveuser |
1166 |
#設置錯誤訊息
|
|
|
1167 |
$result["error"]=$receivedVar;
|
| 226 |
liveuser |
1168 |
|
| 3 |
liveuser |
1169 |
#回傳結果
|
|
|
1170 |
return $result;
|
| 226 |
liveuser |
1171 |
|
| 3 |
liveuser |
1172 |
}#if end
|
| 226 |
liveuser |
1173 |
|
| 3 |
liveuser |
1174 |
#初始化轉好的session變數數值陣列
|
| 171 |
liveuser |
1175 |
$sessionValueArray=array();
|
| 226 |
liveuser |
1176 |
|
| 3 |
liveuser |
1177 |
#建立要轉換成session變數的form變數數值陣列
|
|
|
1178 |
foreach($conf["checkedVarName"] as $value){
|
| 226 |
liveuser |
1179 |
|
| 3 |
liveuser |
1180 |
#取得要轉換成session變數的form變數數值內容
|
|
|
1181 |
$sessionValueArray[]=$receivedVar["inputDataContent"][$value];
|
| 226 |
liveuser |
1182 |
|
| 171 |
liveuser |
1183 |
}#foreach end
|
| 226 |
liveuser |
1184 |
|
| 3 |
liveuser |
1185 |
#函式說明:
|
|
|
1186 |
#建立多個session變數
|
|
|
1187 |
#回傳結果:
|
|
|
1188 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗.
|
|
|
1189 |
#$reuslt["function"],當前執行的函數.
|
|
|
1190 |
#$result["error"],錯誤訊息陣列.
|
|
|
1191 |
#必填參數:
|
|
|
1192 |
#$conf["session.createMulti"]["sessionArrayName"],字串陣列,要建立的session陣列變數名稱,建議可採用name1.name2.name3的格式。
|
|
|
1193 |
$conf["session.createMulti"]["sessionArrayName"]=$conf["sessionArrayName"];
|
|
|
1194 |
#$conf["session.createMulti"]["sessionArrayValue"],字串陣列,session變數的內容要存放什麼呢?
|
|
|
1195 |
$conf["session.createMulti"]["sessionArrayValue"]=$sessionValueArray;
|
|
|
1196 |
#可省略參數:
|
|
|
1197 |
#無
|
|
|
1198 |
$createSessionVarStatus=session::createMulti($conf["session.createMulti"]);
|
| 171 |
liveuser |
1199 |
unset($conf["session.createMulti"]);
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
#如果建立session變數失敗
|
|
|
1202 |
if($createSessionVarStatus["status"]=="false"){
|
| 226 |
liveuser |
1203 |
|
| 3 |
liveuser |
1204 |
#設置執行不正常
|
|
|
1205 |
$result["status"]="false";
|
| 226 |
liveuser |
1206 |
|
| 3 |
liveuser |
1207 |
#設置錯誤訊息
|
|
|
1208 |
$reuslt["error"]=$createSessionVarStatus;
|
| 226 |
liveuser |
1209 |
|
| 3 |
liveuser |
1210 |
#回傳結果
|
|
|
1211 |
return $result;
|
| 226 |
liveuser |
1212 |
|
| 3 |
liveuser |
1213 |
}#if end
|
| 226 |
liveuser |
1214 |
|
| 3 |
liveuser |
1215 |
#執行到這邊代表執行正常
|
|
|
1216 |
$result["status"]="true";
|
| 226 |
liveuser |
1217 |
|
| 3 |
liveuser |
1218 |
#回傳結果
|
|
|
1219 |
return $result;
|
| 226 |
liveuser |
1220 |
|
| 3 |
liveuser |
1221 |
}#function formVarToSession end
|
| 226 |
liveuser |
1222 |
|
| 3 |
liveuser |
1223 |
/*
|
|
|
1224 |
#函式說明:
|
| 226 |
liveuser |
1225 |
#取得指定的session數值
|
| 3 |
liveuser |
1226 |
#回傳結果:
|
|
|
1227 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1228 |
#$result["error"],錯誤訊息.
|
|
|
1229 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
1230 |
#$result["content"],session變數的內容
|
|
|
1231 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
1232 |
#$result["function"],當前執行的函數名稱.
|
|
|
1233 |
#$result["argu"],使用的參數.
|
|
|
1234 |
#必填參數:
|
|
|
1235 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
1236 |
$conf["key"]=array();
|
|
|
1237 |
#可省略參數:
|
| 171 |
liveuser |
1238 |
#$conf["unsetSess"],字串,是否要於成功取得session變數後,將之移除,預設為"false"代表不移除;反之為"true".
|
|
|
1239 |
#$conf["unsetSess"]="false";
|
| 3 |
liveuser |
1240 |
#參考資料:
|
|
|
1241 |
#無.
|
|
|
1242 |
#備註:
|
|
|
1243 |
#無.
|
|
|
1244 |
*/
|
|
|
1245 |
public static function getVal(&$conf){
|
| 226 |
liveuser |
1246 |
|
| 3 |
liveuser |
1247 |
#初始化要回傳的結果
|
|
|
1248 |
$result=array();
|
|
|
1249 |
|
|
|
1250 |
#取得當前執行的函數名稱
|
|
|
1251 |
$result["function"]=__FUNCTION__;
|
|
|
1252 |
|
|
|
1253 |
#如果沒有參數
|
|
|
1254 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1255 |
|
| 3 |
liveuser |
1256 |
#設置執行失敗
|
|
|
1257 |
$result["status"]="false";
|
| 226 |
liveuser |
1258 |
|
| 3 |
liveuser |
1259 |
#設置執行錯誤訊息
|
|
|
1260 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1261 |
|
| 3 |
liveuser |
1262 |
#回傳結果
|
|
|
1263 |
return $result;
|
| 226 |
liveuser |
1264 |
|
| 3 |
liveuser |
1265 |
}#if end
|
| 226 |
liveuser |
1266 |
|
| 3 |
liveuser |
1267 |
#取得參數
|
|
|
1268 |
$result["argu"]=$conf;
|
|
|
1269 |
|
|
|
1270 |
#如果 $conf 不為陣列
|
|
|
1271 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
1272 |
|
| 3 |
liveuser |
1273 |
#設置執行失敗
|
|
|
1274 |
$result["status"]="false";
|
| 226 |
liveuser |
1275 |
|
| 3 |
liveuser |
1276 |
#設置執行錯誤訊息
|
|
|
1277 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1278 |
|
| 3 |
liveuser |
1279 |
#如果傳入的參數為 null
|
|
|
1280 |
if($conf===null){
|
| 226 |
liveuser |
1281 |
|
| 3 |
liveuser |
1282 |
#設置執行錯誤訊息
|
|
|
1283 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1284 |
|
| 3 |
liveuser |
1285 |
}#if end
|
|
|
1286 |
|
|
|
1287 |
#回傳結果
|
|
|
1288 |
return $result;
|
| 226 |
liveuser |
1289 |
|
| 3 |
liveuser |
1290 |
}#if end
|
| 226 |
liveuser |
1291 |
|
| 3 |
liveuser |
1292 |
#檢查參數
|
|
|
1293 |
#函式說明:
|
|
|
1294 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1295 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1296 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1297 |
#$result["function"],當前執行的函式名稱.
|
|
|
1298 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1299 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1300 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1301 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1302 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1303 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1304 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1305 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1306 |
#必填寫的參數:
|
|
|
1307 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1308 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1309 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1310 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key");
|
|
|
1311 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1312 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
1313 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1314 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1315 |
#可以省略的參數:
|
|
|
1316 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1317 |
#$conf["canBeEmptyString"]="false";
|
|
|
1318 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1319 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1320 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1321 |
#$conf["canBeEmpty"]=array();
|
|
|
1322 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1323 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1324 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 171 |
liveuser |
1325 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("unsetSess");
|
| 226 |
liveuser |
1326 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 171 |
liveuser |
1327 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
| 3 |
liveuser |
1328 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 171 |
liveuser |
1329 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
| 3 |
liveuser |
1330 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1331 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1332 |
#參考資料來源:
|
|
|
1333 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1334 |
#建議:
|
|
|
1335 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
1336 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1337 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1338 |
|
| 3 |
liveuser |
1339 |
#若檢查參數失敗
|
|
|
1340 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
1341 |
|
| 3 |
liveuser |
1342 |
#設置執行失敗
|
|
|
1343 |
$result["status"]="false";
|
| 226 |
liveuser |
1344 |
|
| 3 |
liveuser |
1345 |
#設置執行錯誤訊息
|
|
|
1346 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1347 |
|
| 3 |
liveuser |
1348 |
#回傳結果
|
|
|
1349 |
return $result;
|
| 226 |
liveuser |
1350 |
|
| 3 |
liveuser |
1351 |
}#if end
|
| 226 |
liveuser |
1352 |
|
| 3 |
liveuser |
1353 |
#若檢查參數不通過
|
|
|
1354 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
1355 |
|
| 3 |
liveuser |
1356 |
#設置執行失敗
|
|
|
1357 |
$result["status"]="false";
|
| 226 |
liveuser |
1358 |
|
| 3 |
liveuser |
1359 |
#設置執行錯誤訊息
|
|
|
1360 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1361 |
|
| 3 |
liveuser |
1362 |
#回傳結果
|
|
|
1363 |
return $result;
|
| 226 |
liveuser |
1364 |
|
| 3 |
liveuser |
1365 |
}#if end
|
| 226 |
liveuser |
1366 |
|
| 3 |
liveuser |
1367 |
#取得session的副本
|
|
|
1368 |
$session=$_SESSION;
|
| 226 |
liveuser |
1369 |
|
| 3 |
liveuser |
1370 |
#儲存session的位址
|
|
|
1371 |
$sessionAddress=&$_SESSION;
|
| 226 |
liveuser |
1372 |
|
| 3 |
liveuser |
1373 |
#針對每個key
|
|
|
1374 |
foreach($conf["key"] as $keyVal){
|
| 226 |
liveuser |
1375 |
|
| 3 |
liveuser |
1376 |
#如果 key 為 $keyVal 的 session 變數不存在
|
|
|
1377 |
if(!isset($session[$keyVal])){
|
| 226 |
liveuser |
1378 |
|
|
|
1379 |
#設置執行正常
|
| 3 |
liveuser |
1380 |
$result["status"]="true";
|
| 226 |
liveuser |
1381 |
|
| 3 |
liveuser |
1382 |
#設置未找到session變數
|
|
|
1383 |
$result["founded"]="false";
|
| 226 |
liveuser |
1384 |
|
| 3 |
liveuser |
1385 |
#取得 session 的位址
|
|
|
1386 |
$result["address"]=&$sessionAddress;
|
| 226 |
liveuser |
1387 |
|
| 3 |
liveuser |
1388 |
#回傳結果
|
|
|
1389 |
return $result;
|
| 226 |
liveuser |
1390 |
|
| 3 |
liveuser |
1391 |
}#if end
|
| 226 |
liveuser |
1392 |
|
| 3 |
liveuser |
1393 |
#反之
|
|
|
1394 |
else{
|
| 226 |
liveuser |
1395 |
|
| 3 |
liveuser |
1396 |
#取得 session 該層的內容
|
|
|
1397 |
$session=$session[$keyVal];
|
| 226 |
liveuser |
1398 |
|
| 3 |
liveuser |
1399 |
#取得 session 的位址
|
|
|
1400 |
$sessionAddress=&$sessionAddress[$keyVal];
|
| 226 |
liveuser |
1401 |
|
| 171 |
liveuser |
1402 |
#如果要卸除 session 變數
|
|
|
1403 |
if($conf["unsetSess"]==="true"){
|
| 226 |
liveuser |
1404 |
|
| 171 |
liveuser |
1405 |
#卸除 session 變數
|
|
|
1406 |
unset($sessionAddress);
|
| 226 |
liveuser |
1407 |
|
| 171 |
liveuser |
1408 |
}#if end
|
| 226 |
liveuser |
1409 |
|
| 3 |
liveuser |
1410 |
}#else end
|
| 226 |
liveuser |
1411 |
|
| 3 |
liveuser |
1412 |
}#foreach end
|
| 226 |
liveuser |
1413 |
|
| 3 |
liveuser |
1414 |
#設置執行正常
|
|
|
1415 |
$result["status"]="true";
|
| 226 |
liveuser |
1416 |
|
| 3 |
liveuser |
1417 |
#設置有找到 session 變數
|
|
|
1418 |
$result["founded"]="true";
|
| 226 |
liveuser |
1419 |
|
| 3 |
liveuser |
1420 |
#設置取得的session內容
|
|
|
1421 |
$result["content"]=$session;
|
| 226 |
liveuser |
1422 |
|
| 3 |
liveuser |
1423 |
#取得 session 的位址
|
|
|
1424 |
$result["address"]=&$sessionAddress;
|
| 226 |
liveuser |
1425 |
|
| 3 |
liveuser |
1426 |
#回傳結果
|
|
|
1427 |
return $result;
|
| 226 |
liveuser |
1428 |
|
| 3 |
liveuser |
1429 |
}#function getVal end
|
| 226 |
liveuser |
1430 |
|
| 3 |
liveuser |
1431 |
/*
|
|
|
1432 |
#函式說明:
|
| 226 |
liveuser |
1433 |
#設置指定的session變數
|
| 3 |
liveuser |
1434 |
#回傳結果:
|
|
|
1435 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1436 |
#$result["error"],錯誤訊息.
|
|
|
1437 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
1438 |
#$result["content"],session變數的內容
|
|
|
1439 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
1440 |
#$result["function"],當前執行的函數名稱.
|
|
|
1441 |
#$result["argu"],使用的參數.
|
|
|
1442 |
#必填參數:
|
|
|
1443 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
1444 |
$conf["key"]=array();
|
|
|
1445 |
#$conf["val"],任意型態,指定的session變數內容.
|
|
|
1446 |
$conf["val"]=$var;
|
|
|
1447 |
#可省略參數:
|
|
|
1448 |
#$conf["storeAsNotRepeatArray"],字串,"true"代表要將變數內容存成陣列,預設為"false".
|
|
|
1449 |
#$conf["storeAsNotRepeatArray"]="false";
|
|
|
1450 |
#參考資料:
|
|
|
1451 |
#http://php.net/manual/en/function.array-keys.php
|
|
|
1452 |
#http://php.net/manual/en/function.end.php
|
|
|
1453 |
#備註:
|
|
|
1454 |
#無.
|
|
|
1455 |
*/
|
|
|
1456 |
public static function setVal(&$conf){
|
| 226 |
liveuser |
1457 |
|
| 3 |
liveuser |
1458 |
#初始化要回傳的結果
|
|
|
1459 |
$result=array();
|
|
|
1460 |
|
|
|
1461 |
#取得當前執行的函數名稱
|
|
|
1462 |
$result["function"]=__FUNCTION__;
|
|
|
1463 |
|
|
|
1464 |
#如果沒有參數
|
|
|
1465 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1466 |
|
| 3 |
liveuser |
1467 |
#設置執行失敗
|
|
|
1468 |
$result["status"]="false";
|
| 226 |
liveuser |
1469 |
|
| 3 |
liveuser |
1470 |
#設置執行錯誤訊息
|
|
|
1471 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1472 |
|
| 3 |
liveuser |
1473 |
#回傳結果
|
|
|
1474 |
return $result;
|
| 226 |
liveuser |
1475 |
|
| 3 |
liveuser |
1476 |
}#if end
|
| 226 |
liveuser |
1477 |
|
| 3 |
liveuser |
1478 |
#取得參數
|
|
|
1479 |
$result["argu"]=$conf;
|
|
|
1480 |
|
|
|
1481 |
#如果 $conf 不為陣列
|
|
|
1482 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
1483 |
|
| 3 |
liveuser |
1484 |
#設置執行失敗
|
|
|
1485 |
$result["status"]="false";
|
| 226 |
liveuser |
1486 |
|
| 3 |
liveuser |
1487 |
#設置執行錯誤訊息
|
|
|
1488 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1489 |
|
| 3 |
liveuser |
1490 |
#如果傳入的參數為 null
|
|
|
1491 |
if($conf===null){
|
| 226 |
liveuser |
1492 |
|
| 3 |
liveuser |
1493 |
#設置執行錯誤訊息
|
|
|
1494 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1495 |
|
| 3 |
liveuser |
1496 |
}#if end
|
|
|
1497 |
|
|
|
1498 |
#回傳結果
|
|
|
1499 |
return $result;
|
| 226 |
liveuser |
1500 |
|
| 3 |
liveuser |
1501 |
}#if end
|
| 226 |
liveuser |
1502 |
|
| 3 |
liveuser |
1503 |
#檢查參數
|
|
|
1504 |
#函式說明:
|
|
|
1505 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1506 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1507 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1508 |
#$result["function"],當前執行的函式名稱.
|
|
|
1509 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1510 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1511 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1512 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1513 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1514 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1515 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1516 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1517 |
#必填寫的參數:
|
|
|
1518 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1519 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1520 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1521 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","val");
|
|
|
1522 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1523 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","any");
|
|
|
1524 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1525 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1526 |
#可以省略的參數:
|
|
|
1527 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1528 |
#$conf["canBeEmptyString"]="false";
|
|
|
1529 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1530 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1531 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1532 |
#$conf["canBeEmpty"]=array();
|
|
|
1533 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1534 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1535 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1536 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("storeAsNotRepeatArray");
|
| 226 |
liveuser |
1537 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1538 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1539 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1540 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
1541 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1542 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1543 |
#參考資料來源:
|
|
|
1544 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1545 |
#建議:
|
|
|
1546 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
1547 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1548 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1549 |
|
| 3 |
liveuser |
1550 |
#若檢查參數失敗
|
|
|
1551 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
1552 |
|
| 3 |
liveuser |
1553 |
#設置執行失敗
|
|
|
1554 |
$result["status"]="false";
|
| 226 |
liveuser |
1555 |
|
| 3 |
liveuser |
1556 |
#設置執行錯誤訊息
|
|
|
1557 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1558 |
|
| 3 |
liveuser |
1559 |
#回傳結果
|
|
|
1560 |
return $result;
|
| 226 |
liveuser |
1561 |
|
| 3 |
liveuser |
1562 |
}#if end
|
| 226 |
liveuser |
1563 |
|
| 3 |
liveuser |
1564 |
#若檢查參數不通過
|
|
|
1565 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
1566 |
|
| 3 |
liveuser |
1567 |
#設置執行失敗
|
|
|
1568 |
$result["status"]="false";
|
| 226 |
liveuser |
1569 |
|
| 3 |
liveuser |
1570 |
#設置執行錯誤訊息
|
|
|
1571 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1572 |
|
| 3 |
liveuser |
1573 |
#回傳結果
|
|
|
1574 |
return $result;
|
| 226 |
liveuser |
1575 |
|
| 3 |
liveuser |
1576 |
}#if end
|
| 226 |
liveuser |
1577 |
|
| 3 |
liveuser |
1578 |
#取得seesion變數的層級數目
|
|
|
1579 |
$lastLayer=count($conf["key"]);
|
| 226 |
liveuser |
1580 |
|
| 3 |
liveuser |
1581 |
#設置初始的層級
|
| 226 |
liveuser |
1582 |
$layer=1;
|
|
|
1583 |
|
| 3 |
liveuser |
1584 |
#取得session變數的位址
|
|
|
1585 |
$session=&$_SESSION;
|
| 226 |
liveuser |
1586 |
|
| 3 |
liveuser |
1587 |
#數化要查詢的session key階層
|
| 226 |
liveuser |
1588 |
$sa=array();
|
|
|
1589 |
|
| 3 |
liveuser |
1590 |
#針對session變數的每個層級
|
|
|
1591 |
foreach($conf["key"] as $keyVal){
|
| 226 |
liveuser |
1592 |
|
| 3 |
liveuser |
1593 |
#如果是最後一層
|
|
|
1594 |
if($layer===$lastLayer){
|
| 226 |
liveuser |
1595 |
|
| 3 |
liveuser |
1596 |
#如果要儲存成陣列
|
|
|
1597 |
if($conf["storeAsNotRepeatArray"]==="true"){
|
| 226 |
liveuser |
1598 |
|
| 3 |
liveuser |
1599 |
#如果目標變數有存在了
|
|
|
1600 |
if(isset($session[$keyVal])){
|
| 226 |
liveuser |
1601 |
|
| 3 |
liveuser |
1602 |
#如果不是陣列
|
|
|
1603 |
if(gettype($session[$keyVal])!=="array"){
|
| 226 |
liveuser |
1604 |
|
| 3 |
liveuser |
1605 |
#設置執行失敗
|
|
|
1606 |
$result["status"]="false";
|
| 226 |
liveuser |
1607 |
|
| 3 |
liveuser |
1608 |
#設置執行錯誤訊息
|
|
|
1609 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1610 |
|
| 3 |
liveuser |
1611 |
#設置錯誤訊息
|
|
|
1612 |
$result["error"][]="變數內容不是陣列";
|
| 226 |
liveuser |
1613 |
|
| 3 |
liveuser |
1614 |
#回傳結果
|
|
|
1615 |
return $result;
|
| 226 |
liveuser |
1616 |
|
| 3 |
liveuser |
1617 |
}#if end
|
| 226 |
liveuser |
1618 |
|
| 3 |
liveuser |
1619 |
#如果是新的元素
|
|
|
1620 |
if(!in_array($conf["val"],$session[$keyVal])){
|
| 226 |
liveuser |
1621 |
|
| 3 |
liveuser |
1622 |
#新增元素
|
|
|
1623 |
$session[$keyVal][]=$conf["val"];
|
| 226 |
liveuser |
1624 |
|
| 3 |
liveuser |
1625 |
}#if end
|
| 226 |
liveuser |
1626 |
|
| 3 |
liveuser |
1627 |
}#if end
|
| 226 |
liveuser |
1628 |
|
| 3 |
liveuser |
1629 |
#反之
|
|
|
1630 |
else{
|
| 226 |
liveuser |
1631 |
|
| 3 |
liveuser |
1632 |
#新增元素
|
|
|
1633 |
$session[$keyVal][]=$conf["val"];
|
| 226 |
liveuser |
1634 |
|
| 3 |
liveuser |
1635 |
}#else end
|
| 226 |
liveuser |
1636 |
|
| 3 |
liveuser |
1637 |
$keys=array_keys($session[$keyVal]);
|
| 226 |
liveuser |
1638 |
|
| 3 |
liveuser |
1639 |
#get last key
|
|
|
1640 |
$lastKey=end($keys);
|
| 226 |
liveuser |
1641 |
|
| 3 |
liveuser |
1642 |
#取得當前參照的session階層位址
|
| 226 |
liveuser |
1643 |
$session=&$session[$keyVal][$lastKey];
|
|
|
1644 |
|
| 3 |
liveuser |
1645 |
}#if end
|
| 226 |
liveuser |
1646 |
|
| 3 |
liveuser |
1647 |
#反之直接儲存
|
|
|
1648 |
else{
|
| 226 |
liveuser |
1649 |
|
| 3 |
liveuser |
1650 |
#設置 session 變數的內容
|
| 226 |
liveuser |
1651 |
$session[$keyVal]=$conf["val"];
|
|
|
1652 |
|
| 3 |
liveuser |
1653 |
#取得當前參照的session階層位址
|
| 226 |
liveuser |
1654 |
$session=&$session[$keyVal];
|
| 3 |
liveuser |
1655 |
|
|
|
1656 |
}#else end
|
| 226 |
liveuser |
1657 |
|
| 3 |
liveuser |
1658 |
#跳出迴圈
|
|
|
1659 |
break;
|
| 226 |
liveuser |
1660 |
|
| 3 |
liveuser |
1661 |
}#if end
|
| 226 |
liveuser |
1662 |
|
| 3 |
liveuser |
1663 |
#設置要檢查的session key階層
|
|
|
1664 |
$sa[]=$keyVal;
|
| 226 |
liveuser |
1665 |
|
| 3 |
liveuser |
1666 |
#函式說明:
|
| 226 |
liveuser |
1667 |
#取得指定的session數值
|
| 3 |
liveuser |
1668 |
#回傳結果:
|
|
|
1669 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1670 |
#$result["error"],錯誤訊息.
|
|
|
1671 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
1672 |
#$result["content"],session變數的內容
|
|
|
1673 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
1674 |
#$result["function"],當前執行的函數名稱.
|
|
|
1675 |
#$result["argu"],使用的參數.
|
|
|
1676 |
#必填參數:
|
|
|
1677 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
1678 |
$conf["session::getVal"]["key"]=$sa;
|
|
|
1679 |
$getVal=session::getVal($conf["session::getVal"]);
|
| 226 |
liveuser |
1680 |
unset($conf["session::getVal"]);
|
|
|
1681 |
|
| 3 |
liveuser |
1682 |
#如果取得 session key 的內容失敗
|
|
|
1683 |
if($getVal["status"]==="false"){
|
| 226 |
liveuser |
1684 |
|
| 3 |
liveuser |
1685 |
#設置執行失敗
|
|
|
1686 |
$result["status"]="false";
|
| 226 |
liveuser |
1687 |
|
| 3 |
liveuser |
1688 |
#設置執行錯誤訊息
|
|
|
1689 |
$result["error"]=$getVal;
|
| 226 |
liveuser |
1690 |
|
| 3 |
liveuser |
1691 |
#回傳結果
|
|
|
1692 |
return $result;
|
| 226 |
liveuser |
1693 |
|
| 3 |
liveuser |
1694 |
}#if end
|
| 226 |
liveuser |
1695 |
|
| 3 |
liveuser |
1696 |
#如果 session 不存在
|
|
|
1697 |
if($getVal["founded"]==="false"){
|
| 226 |
liveuser |
1698 |
|
| 3 |
liveuser |
1699 |
#建立該 session 階層並設為空陣列
|
|
|
1700 |
$getVal["address"][$keyVal]=array();
|
| 226 |
liveuser |
1701 |
|
| 3 |
liveuser |
1702 |
#取得當前參照的session階層位址
|
| 226 |
liveuser |
1703 |
$session=&$getVal["address"][$keyVal];
|
|
|
1704 |
|
|
|
1705 |
}#if end
|
|
|
1706 |
|
|
|
1707 |
#如果 session 存在
|
| 3 |
liveuser |
1708 |
else{
|
| 226 |
liveuser |
1709 |
|
| 3 |
liveuser |
1710 |
#取得當前參照的session階層位址
|
|
|
1711 |
$session=&$getVal["address"];
|
| 226 |
liveuser |
1712 |
|
|
|
1713 |
}#else end
|
|
|
1714 |
|
| 3 |
liveuser |
1715 |
#層級加一
|
|
|
1716 |
$layer++;
|
| 226 |
liveuser |
1717 |
|
| 3 |
liveuser |
1718 |
}#foreach end
|
| 226 |
liveuser |
1719 |
|
| 3 |
liveuser |
1720 |
#設置執行正常
|
|
|
1721 |
$result["status"]="true";
|
| 226 |
liveuser |
1722 |
|
| 3 |
liveuser |
1723 |
#設置session變數的位址
|
|
|
1724 |
$result["address"]=&$session;
|
| 226 |
liveuser |
1725 |
|
| 3 |
liveuser |
1726 |
#回傳節果
|
|
|
1727 |
return $result;
|
| 226 |
liveuser |
1728 |
|
| 3 |
liveuser |
1729 |
}#function setVal end
|
| 226 |
liveuser |
1730 |
|
| 3 |
liveuser |
1731 |
/*
|
|
|
1732 |
#函式說明:
|
| 226 |
liveuser |
1733 |
#設置多個session變數的內容
|
| 3 |
liveuser |
1734 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1735 |
#$result["error"],錯誤訊息.
|
|
|
1736 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
1737 |
#$result["content"],每個設置好的session變數資訊
|
|
|
1738 |
#$result["function"],當前執行的函數名稱.
|
|
|
1739 |
#$result["argu"],使用的參數.
|
|
|
1740 |
#必填參數:
|
|
|
1741 |
#$conf["key"],二維陣列,每個session的key名稱與層級.
|
|
|
1742 |
$conf["key"]=array(array());
|
|
|
1743 |
#$conf["val"],陣列,每個指定的session變數內容.
|
|
|
1744 |
$conf["val"]=array($var);
|
|
|
1745 |
#可省略參數:
|
|
|
1746 |
#$conf["storeAsNotRepeatArray"],字串,"true"代表要將變數內容存成陣列,預設為"false".
|
|
|
1747 |
#$conf["storeAsNotRepeatArray"]="false";
|
|
|
1748 |
#參考資料:
|
|
|
1749 |
#無.
|
|
|
1750 |
#備註:
|
|
|
1751 |
#無.
|
|
|
1752 |
*/
|
|
|
1753 |
public static function setMultiVal(&$conf){
|
| 226 |
liveuser |
1754 |
|
| 3 |
liveuser |
1755 |
#初始化要回傳的結果
|
|
|
1756 |
$result=array();
|
|
|
1757 |
|
|
|
1758 |
#取得當前執行的函數名稱
|
|
|
1759 |
$result["function"]=__FUNCTION__;
|
|
|
1760 |
|
|
|
1761 |
#如果沒有參數
|
|
|
1762 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1763 |
|
| 3 |
liveuser |
1764 |
#設置執行失敗
|
|
|
1765 |
$result["status"]="false";
|
| 226 |
liveuser |
1766 |
|
| 3 |
liveuser |
1767 |
#設置執行錯誤訊息
|
|
|
1768 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1769 |
|
| 3 |
liveuser |
1770 |
#回傳結果
|
|
|
1771 |
return $result;
|
| 226 |
liveuser |
1772 |
|
| 3 |
liveuser |
1773 |
}#if end
|
| 226 |
liveuser |
1774 |
|
| 3 |
liveuser |
1775 |
#取得參數
|
|
|
1776 |
$result["argu"]=$conf;
|
|
|
1777 |
|
|
|
1778 |
#如果 $conf 不為陣列
|
|
|
1779 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
1780 |
|
| 3 |
liveuser |
1781 |
#設置執行失敗
|
|
|
1782 |
$result["status"]="false";
|
| 226 |
liveuser |
1783 |
|
| 3 |
liveuser |
1784 |
#設置執行錯誤訊息
|
|
|
1785 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1786 |
|
| 3 |
liveuser |
1787 |
#如果傳入的參數為 null
|
|
|
1788 |
if($conf===null){
|
| 226 |
liveuser |
1789 |
|
| 3 |
liveuser |
1790 |
#設置執行錯誤訊息
|
|
|
1791 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1792 |
|
| 3 |
liveuser |
1793 |
}#if end
|
|
|
1794 |
|
|
|
1795 |
#回傳結果
|
|
|
1796 |
return $result;
|
| 226 |
liveuser |
1797 |
|
| 3 |
liveuser |
1798 |
}#if end
|
| 226 |
liveuser |
1799 |
|
| 3 |
liveuser |
1800 |
#檢查參數
|
|
|
1801 |
#函式說明:
|
|
|
1802 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1803 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1804 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1805 |
#$result["function"],當前執行的函式名稱.
|
|
|
1806 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1807 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1808 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1809 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1810 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1811 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1812 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1813 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1814 |
#必填寫的參數:
|
|
|
1815 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1816 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1817 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1818 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","val");
|
|
|
1819 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1820 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array");
|
|
|
1821 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1822 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1823 |
#可以省略的參數:
|
|
|
1824 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1825 |
#$conf["canBeEmptyString"]="false";
|
|
|
1826 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1827 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1828 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1829 |
#$conf["canBeEmpty"]=array();
|
|
|
1830 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1831 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1832 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1833 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("storeAsNotRepeatArray");
|
| 226 |
liveuser |
1834 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1835 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1836 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1837 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
1838 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1839 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("key","val");
|
|
|
1840 |
#參考資料來源:
|
|
|
1841 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1842 |
#建議:
|
|
|
1843 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
1844 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1845 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1846 |
|
| 3 |
liveuser |
1847 |
#若檢查參數失敗
|
|
|
1848 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
1849 |
|
| 3 |
liveuser |
1850 |
#設置執行失敗
|
|
|
1851 |
$result["status"]="false";
|
| 226 |
liveuser |
1852 |
|
| 3 |
liveuser |
1853 |
#設置執行錯誤訊息
|
|
|
1854 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1855 |
|
| 3 |
liveuser |
1856 |
#回傳結果
|
|
|
1857 |
return $result;
|
| 226 |
liveuser |
1858 |
|
| 3 |
liveuser |
1859 |
}#if end
|
| 226 |
liveuser |
1860 |
|
| 3 |
liveuser |
1861 |
#若檢查參數不通過
|
|
|
1862 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
1863 |
|
| 3 |
liveuser |
1864 |
#設置執行失敗
|
|
|
1865 |
$result["status"]="false";
|
| 226 |
liveuser |
1866 |
|
| 3 |
liveuser |
1867 |
#設置執行錯誤訊息
|
|
|
1868 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1869 |
|
| 3 |
liveuser |
1870 |
#回傳結果
|
|
|
1871 |
return $result;
|
| 226 |
liveuser |
1872 |
|
| 3 |
liveuser |
1873 |
}#if end
|
| 226 |
liveuser |
1874 |
|
| 3 |
liveuser |
1875 |
#針對每個 $conf["key"]
|
|
|
1876 |
foreach($conf["key"] as $index=>$keyVal){
|
| 226 |
liveuser |
1877 |
|
|
|
1878 |
#設置指定的session變數
|
| 3 |
liveuser |
1879 |
#回傳結果:
|
|
|
1880 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1881 |
#$result["error"],錯誤訊息.
|
|
|
1882 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
1883 |
#$result["content"],session變數的內容
|
|
|
1884 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
1885 |
#$result["function"],當前執行的函數名稱.
|
|
|
1886 |
#$result["argu"],使用的參數.
|
|
|
1887 |
#必填參數:
|
|
|
1888 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
1889 |
$conf["session::setVal"]["key"]=$keyVal;
|
|
|
1890 |
#$conf["val"],任意型態,指定的session變數內容.
|
|
|
1891 |
$conf["session::setVal"]["val"]=$conf["val"][$index];
|
|
|
1892 |
#可省略參數:
|
|
|
1893 |
#$conf["storeAsNotRepeatArray"],字串,"true"代表要將變數內容存成陣列,預設為"false".
|
| 226 |
liveuser |
1894 |
$conf["session::setVal"]["storeAsNotRepeatArray"]=$conf["storeAsNotRepeatArray"];
|
| 3 |
liveuser |
1895 |
$setVal=session::setVal($conf["session::setVal"]);
|
|
|
1896 |
unset($conf["session::setVal"]);
|
| 226 |
liveuser |
1897 |
|
|
|
1898 |
#如果設置 session 變數失敗
|
| 3 |
liveuser |
1899 |
if($setVal["status"]==="false"){
|
| 226 |
liveuser |
1900 |
|
| 3 |
liveuser |
1901 |
#設置執行失敗
|
|
|
1902 |
$result["status"]="false";
|
| 226 |
liveuser |
1903 |
|
| 3 |
liveuser |
1904 |
#設置執行錯誤訊息
|
|
|
1905 |
$result["error"]=$setVal;
|
| 226 |
liveuser |
1906 |
|
| 3 |
liveuser |
1907 |
#回傳結果
|
|
|
1908 |
return $result;
|
| 226 |
liveuser |
1909 |
|
| 3 |
liveuser |
1910 |
}#if end
|
| 226 |
liveuser |
1911 |
|
| 3 |
liveuser |
1912 |
#取得設置好的結果
|
|
|
1913 |
$result["content"][]=$setVal;
|
| 226 |
liveuser |
1914 |
|
| 3 |
liveuser |
1915 |
}#foreach end
|
| 226 |
liveuser |
1916 |
|
| 3 |
liveuser |
1917 |
#設置執行正常
|
|
|
1918 |
$result["status"]="true";
|
| 226 |
liveuser |
1919 |
|
| 3 |
liveuser |
1920 |
#回傳結果
|
|
|
1921 |
return $result;
|
| 226 |
liveuser |
1922 |
|
| 3 |
liveuser |
1923 |
}#function setMutiVal end
|
| 226 |
liveuser |
1924 |
|
| 3 |
liveuser |
1925 |
}#session class end
|
|
|
1926 |
|
|
|
1927 |
?>
|