Subversion Repositories php-qbpwcf

Rev

Rev 106 | Rev 222 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
<?php
2
 
3
/*
4
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
    Copyright (C) 2015~2023 Min-Jhin,Chen
6
 
7
    This file is part of QBPWCF.
8
 
9
    QBPWCF is free software: you can redistribute it and/or modify
10
    it under the terms of the GNU General Public License as published by
11
    the Free Software Foundation, either version 3 of the License, or
12
    (at your option) any later version.
13
 
14
    QBPWCF is distributed in the hope that it will be useful,
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    GNU General Public License for more details.
18
 
19
    You should have received a copy of the GNU General Public License
20
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
21
 
22
*/
23
 
24
/*
25
 
26
依照來源的內容來將資料塞入到資料庫
27
 
28
*/
29
 
30
#使用命名空間qbpwcf
31
namespace qbpwcf;
32
 
33
#初始化輸出
34
$output=array();
35
 
36
#取得 lib path
106 liveuser 37
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
1 liveuser 38
 
39
#如果執行失敗
40
if($status!==0){
41
 
42
	#debug
43
	var_dump(__LINE__,$output);
44
 
45
	#結束執行,回傳shell 1.
46
	exit(1);
47
 
48
	}#if end
49
 
50
#儲存lib path
51
$folderOfUsrLib=$output[0];
52
 
53
#初始化輸出
54
$output=array();
55
 
56
#以該檔案的實際位置的 lib path 為 include path 首位
106 liveuser 57
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
1 liveuser 58
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
59
 
60
#匯入外部套件
61
include("allInOneForJson.php");
62
 
63
#建議的log位置
183 liveuser 64
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
1 liveuser 65
 
183 liveuser 66
#預設的範例資料參數
67
$params=array();
68
$params["dbSecret"]=$dbSecret;
69
$params["dbAddr"]=$dbAddress;
70
$params["dbPort"]=$dbPort;
71
$params["dbName"]=$dbName;
72
$params["dbUser"]=$dbAccount;
73
$params["dbPass"]=$dbPassword;
74
$params["dtName"]="namespace";
75
$params["cols"]=array("name","comment");
76
$params["vals"]=array("notExist","not exist namespace");
1 liveuser 77
 
183 liveuser 78
#加密參數
79
#函式說明:
80
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
81
#回傳結果:
82
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
83
#$result["function"],當前執行的函數名稱.
84
#$result["content"],加密後的結果.
85
#$result["error"],錯誤訊息陣列.
86
#$result["argu"],使用的參數.
87
#必填參數:
88
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
89
$conf["enCodeStr"]=$params;
90
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
91
$conf["enCodeType"]="qbpwcf";
92
#可省略參數:
93
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
94
#$conf["sha1Raw"]="false";
95
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
96
#$conf["p_hash"]="";
97
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
98
#$conf["keyForAes256"]="";
99
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
100
#$conf["aes256Encode"]="";
101
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
102
#$conf["qbpwcfDecode"]="false";
103
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
104
#$conf["gpgDecrypt"]="false";
105
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
106
#$conf["gpgId"]="";
107
#參考資料:
108
#sha1=>http://php.net/manual/en/function.sha1.php
109
#md5=>http://php.net/manual/en/function.md5.php
110
#password_hash=>http://php.net/manual/en/function.password-hash.php
111
#password_verify=>http://php.net/manual/en/function.password-verify.php
112
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
113
#備註:
114
#無.
115
$enCodeStr=authenticate::enCodeStr($conf);
116
unset($conf);
1 liveuser 117
 
183 liveuser 118
#如果執行異常
119
if($enCodeStr["status"]==="false"){
1 liveuser 120
 
183 liveuser 121
	#函式說明:
122
	#撰寫log
123
	#回傳結果:
124
	#$result["status"],狀態,"true"或"false".
125
	#$result["error"],錯誤訊息陣列.
126
	#$result["function"],當前函式的名稱.
127
	#$result["argu"],使用的參數.
128
	#必填參數:
129
	#$conf["path"],log檔案的路徑與名稱.
130
	$conf["path"]=$logFile;
131
	#$conf["content"],字串,要寫的內容.
132
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
133
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
134
	$conf["fileArgu"]=__FILE__;
135
	#可省略參數:
136
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
137
	#$conf["rewrite"]="false";
138
	#參考資料:
139
	#無.
140
	#備註:
141
	#無.	
142
	$record=logs::record($conf);
143
	unset($conf);
1 liveuser 144
 
183 liveuser 145
	#如果寫log 失敗
146
	if($record["status"]==="false"){
1 liveuser 147
 
183 liveuser 148
		#印出訊息
149
		echo json_encode($record);
150
 
151
		#異常結束執行
152
		exit(1);
1 liveuser 153
 
183 liveuser 154
		}#if end
155
 
156
	#異常結束執行
157
	exit(1);
158
 
159
	}#if end
160
 
161
#加密參數
162
#函式說明:
163
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
164
#回傳結果:
165
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
166
#$result["function"],當前執行的函數名稱.
167
#$result["content"],加密後的結果.
168
#$result["error"],錯誤訊息陣列.
169
#$result["argu"],使用的參數.
170
#必填參數:
171
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
172
$conf["enCodeStr"]=$enCodeStr["content"];
173
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
174
$conf["enCodeType"]="gpg";
175
#可省略參數:
176
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
177
#$conf["sha1Raw"]="false";
178
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
179
#$conf["p_hash"]="";
180
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
181
#$conf["keyForAes256"]="";
182
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
183
#$conf["aes256Encode"]="";
184
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
185
#$conf["qbpwcfDecode"]="false";
186
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
187
$conf["gpgDecrypt"]="false";
188
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
189
#$conf["gpgId"]="";
190
#參考資料:
191
#sha1=>http://php.net/manual/en/function.sha1.php
192
#md5=>http://php.net/manual/en/function.md5.php
193
#password_hash=>http://php.net/manual/en/function.password-hash.php
194
#password_verify=>http://php.net/manual/en/function.password-verify.php
195
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
196
#備註:
197
#無.
198
$enCodeStr=authenticate::enCodeStr($conf);
199
unset($conf);
200
 
201
#如果執行異常
202
if($enCodeStr["status"]==="false"){
203
 
204
	#函式說明:
205
	#撰寫log
206
	#回傳結果:
207
	#$result["status"],狀態,"true"或"false".
208
	#$result["error"],錯誤訊息陣列.
209
	#$result["function"],當前函式的名稱.
210
	#$result["argu"],使用的參數.
211
	#必填參數:
212
	#$conf["path"],log檔案的路徑與名稱.
213
	$conf["path"]=$logFile;
214
	#$conf["content"],字串,要寫的內容.
215
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
216
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
217
	$conf["fileArgu"]=__FILE__;
218
	#可省略參數:
219
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
220
	#$conf["rewrite"]="false";
221
	#參考資料:
222
	#無.
223
	#備註:
224
	#無.	
225
	$record=logs::record($conf);
226
	unset($conf);
227
 
228
	#如果寫log 失敗
229
	if($record["status"]==="false"){
230
 
231
		#印出訊息
232
		echo json_encode($record);
233
 
234
		#異常結束執行
235
		exit(1);
236
 
237
		}#if end
238
 
239
	#異常結束執行
240
	exit(1);
241
 
242
	}#if end
243
 
244
#編碼參數
245
#函式說明:
246
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
247
#回傳結果:
248
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
249
#$result["function"],當前執行的函數名稱.
250
#$result["content"],加密後的結果.
251
#$result["error"],錯誤訊息陣列.
252
#$result["argu"],使用的參數.
253
#必填參數:
254
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
255
$conf["enCodeStr"]=$enCodeStr["content"];
256
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
257
$conf["enCodeType"]="bin2hex";
258
#可省略參數:
259
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
260
#$conf["sha1Raw"]="false";
261
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
262
#$conf["p_hash"]="";
263
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
264
#$conf["keyForAes256"]="";
265
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
266
#$conf["aes256Encode"]="";
267
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
268
#$conf["qbpwcfDecode"]="false";
269
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
270
#$conf["gpgDecrypt"]="false";
271
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
272
#$conf["gpgId"]="";
273
#參考資料:
274
#sha1=>http://php.net/manual/en/function.sha1.php
275
#md5=>http://php.net/manual/en/function.md5.php
276
#password_hash=>http://php.net/manual/en/function.password-hash.php
277
#password_verify=>http://php.net/manual/en/function.password-verify.php
278
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
279
#備註:
280
#無.
281
$enCodeStr=authenticate::enCodeStr($conf);
282
unset($conf);
283
 
284
#如果執行異常
285
if($enCodeStr["status"]==="false"){
286
 
287
	#函式說明:
288
	#撰寫log
289
	#回傳結果:
290
	#$result["status"],狀態,"true"或"false".
291
	#$result["error"],錯誤訊息陣列.
292
	#$result["function"],當前函式的名稱.
293
	#$result["argu"],使用的參數.
294
	#必填參數:
295
	#$conf["path"],log檔案的路徑與名稱.
296
	$conf["path"]=$logFile;
297
	#$conf["content"],字串,要寫的內容.
298
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
299
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
300
	$conf["fileArgu"]=__FILE__;
301
	#可省略參數:
302
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
303
	#$conf["rewrite"]="false";
304
	#參考資料:
305
	#無.
306
	#備註:
307
	#無.	
308
	$record=logs::record($conf);
309
	unset($conf);
310
 
311
	#如果寫log 失敗
312
	if($record["status"]==="false"){
313
 
314
		#印出訊息
315
		echo json_encode($record);
316
 
317
		#異常結束執行
318
		exit(1);
319
 
320
		}#if end
321
 
322
	#異常結束執行
323
	exit(1);
324
 
325
	}#if end
326
 
327
#更新POST的預設參數
328
$_POST["params"]=$enCodeStr["content"];
329
 
1 liveuser 330
#涵式說明:
331
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
332
#回傳的結果:
333
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
334
#$result["error"],錯誤訊息陣列.
335
#$resutl["function"],當前執行的涵式名稱.
336
#$result["warning"],警告訊息陣列.
337
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
338
#$result["lostVarName"],沒有皆收到的變數名稱陣列
339
#$result["inputDataContent"],所接收的參數陣列.
340
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
341
#$result["inputDataCount"],從表單總共接收到幾個元素.
342
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
343
#必填的參數:
344
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
345
$conf["method"]="POST";
346
#可省略的參數:
347
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
348
#$conf["allowGet"]="true";
349
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
350
#$conf["limitPrePage"]=array("");
351
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
352
#$conf["transferLocation"]="";
353
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
354
#$conf["ignore"]=array();
355
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
356
#$conf["correctCharacter"]="false";
357
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
358
$conf["checkedVarName"]=array("params");
359
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
360
#$conf["canBeEmptyString"]="false";
361
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
362
#$conf["sessionNameArray"]=array();
363
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
364
#$conf["unsetSessionArray"]=array();
365
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
366
#$conf["recaptcha_url"]="";
367
#參考資料來源:
368
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
369
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
370
#備註:
371
#表單變數的名稱若含有「.」,則會變成「-」。
372
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
373
unset($conf);
374
 
183 liveuser 375
#如果執行異常
376
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
377
 
378
	#函式說明:
379
	#撰寫log
380
	#回傳結果:
381
	#$result["status"],狀態,"true"或"false".
382
	#$result["error"],錯誤訊息陣列.
383
	#$result["function"],當前函式的名稱.
384
	#$result["argu"],使用的參數.
385
	#必填參數:
386
	#$conf["path"],log檔案的路徑與名稱.
387
	$conf["path"]=$logFile;
388
	#$conf["content"],字串,要寫的內容.
389
	$conf["content"]="Form data error, please see json:".json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
390
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
391
	$conf["fileArgu"]=__FILE__;
392
	#可省略參數:
393
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
394
	#$conf["rewrite"]="false";
395
	#參考資料:
396
	#無.
397
	#備註:
398
	#無.	
399
	$record=logs::record($conf);
400
	unset($conf);
401
 
402
	#如果寫log 失敗
403
	if($record["status"]==="false"){
404
 
405
		#印出訊息
406
		echo json_encode($record);
407
 
408
		#異常結束執行
409
		exit(1);
410
 
411
		}#if end
412
 
413
	#異常結束執行
414
	exit(1);
415
 
416
	}#if end
417
 
1 liveuser 418
#函式說明:
419
#撰寫log
420
#回傳結果:
421
#$result["status"],狀態,"true"或"false".
422
#$result["error"],錯誤訊息陣列.
423
#$result["function"],當前函式的名稱.
424
#$result["argu"],使用的參數.
425
#必填參數:
426
#$conf["path"],log檔案的路徑與名稱.
427
$conf["path"]=$logFile;
428
#$conf["content"],字串,要寫的內容.
429
$conf["content"]=json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
430
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
431
$conf["fileArgu"]=__FILE__;
432
#可省略參數:
433
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
434
#$conf["rewrite"]="false";
435
#參考資料:
436
#無.
437
#備註:
438
#無.	
439
$record=logs::record($conf);
440
unset($conf);
441
 
442
#如果寫log 失敗
443
if($record["status"]==="false"){
444
 
445
	#印出訊息
446
	echo json_encode($record);
447
 
183 liveuser 448
	#異常結束執行
449
	exit(1);
1 liveuser 450
 
451
	}#if end
452
 
183 liveuser 453
#取得參數
454
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];
1 liveuser 455
 
183 liveuser 456
#解碼參數
457
#函式說明:
458
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
459
#回傳結果:
460
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
461
#$result["function"],當前執行的函數名稱.
462
#$result["content"],加密後的結果.
463
#$result["error"],錯誤訊息陣列.
464
#$result["argu"],使用的參數.
465
#必填參數:
466
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
467
$conf["enCodeStr"]=$params;
468
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
469
$conf["enCodeType"]="hex2bin";
470
#可省略參數:
471
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
472
#$conf["sha1Raw"]="false";
473
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
474
#$conf["p_hash"]="";
475
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
476
#$conf["keyForAes256"]="";
477
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
478
#$conf["aes256Encode"]="";
479
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
480
#$conf["qbpwcfDecode"]="false";
481
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
482
#$conf["gpgDecrypt"]="false";
483
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
484
#$conf["gpgId"]="";
485
#參考資料:
486
#sha1=>http://php.net/manual/en/function.sha1.php
487
#md5=>http://php.net/manual/en/function.md5.php
488
#password_hash=>http://php.net/manual/en/function.password-hash.php
489
#password_verify=>http://php.net/manual/en/function.password-verify.php
490
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
491
#備註:
492
#無.
493
$enCodeStr=authenticate::enCodeStr($conf);
494
unset($conf);
1 liveuser 495
 
183 liveuser 496
#debug
497
#var_dump(__LINE__,$enCodeStr);
1 liveuser 498
 
183 liveuser 499
#如果執行異常
500
if($enCodeStr["status"]==="false"){
501
 
502
	#函式說明:
503
	#撰寫log
504
	#回傳結果:
505
	#$result["status"],狀態,"true"或"false".
506
	#$result["error"],錯誤訊息陣列.
507
	#$result["function"],當前函式的名稱.
508
	#$result["argu"],使用的參數.
509
	#必填參數:
510
	#$conf["path"],log檔案的路徑與名稱.
511
	$conf["path"]=$logFile;
512
	#$conf["content"],字串,要寫的內容.
513
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
514
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
515
	$conf["fileArgu"]=__FILE__;
516
	#可省略參數:
517
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
518
	#$conf["rewrite"]="false";
519
	#參考資料:
520
	#無.
521
	#備註:
522
	#無.	
523
	$record=logs::record($conf);
524
	unset($conf);
525
 
526
	#如果寫log 失敗
527
	if($record["status"]==="false"){
528
 
529
		#印出訊息
530
		echo json_encode($record);
531
 
532
		#異常結束執行
533
		exit(1);
534
 
535
		}#if end
536
 
537
	#異常結束執行
538
	exit(1);
539
 
1 liveuser 540
	}#if end
541
 
183 liveuser 542
#解密參數
543
#函式說明:
544
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
545
#回傳結果:
546
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
547
#$result["function"],當前執行的函數名稱.
548
#$result["content"],加密後的結果.
549
#$result["error"],錯誤訊息陣列.
550
#$result["argu"],使用的參數.
551
#必填參數:
552
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
553
$conf["enCodeStr"]=$enCodeStr["content"];
554
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
555
$conf["enCodeType"]="gpg";
556
#可省略參數:
557
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
558
#$conf["sha1Raw"]="false";
559
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
560
#$conf["p_hash"]="";
561
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
562
#$conf["keyForAes256"]="";
563
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
564
#$conf["aes256Encode"]="";
565
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
566
#$conf["qbpwcfDecode"]="true";
567
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
568
$conf["gpgDecrypt"]="true";
569
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
570
#$conf["gpgId"]="";
571
#參考資料:
572
#sha1=>http://php.net/manual/en/function.sha1.php
573
#md5=>http://php.net/manual/en/function.md5.php
574
#password_hash=>http://php.net/manual/en/function.password-hash.php
575
#password_verify=>http://php.net/manual/en/function.password-verify.php
576
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
577
#備註:
578
#無.
579
$enCodeStr=authenticate::enCodeStr($conf);
580
unset($conf);
1 liveuser 581
 
183 liveuser 582
#debug
583
#var_dump(__LINE__,$enCodeStr);exit;
1 liveuser 584
 
183 liveuser 585
#如果執行異常
586
if($enCodeStr["status"]==="false"){
1 liveuser 587
 
183 liveuser 588
	#函式說明:
589
	#撰寫log
590
	#回傳結果:
591
	#$result["status"],狀態,"true"或"false".
592
	#$result["error"],錯誤訊息陣列.
593
	#$result["function"],當前函式的名稱.
594
	#$result["argu"],使用的參數.
595
	#必填參數:
596
	#$conf["path"],log檔案的路徑與名稱.
597
	$conf["path"]=$logFile;
598
	#$conf["content"],字串,要寫的內容.
599
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
600
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
601
	$conf["fileArgu"]=__FILE__;
602
	#可省略參數:
603
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
604
	#$conf["rewrite"]="false";
605
	#參考資料:
606
	#無.
607
	#備註:
608
	#無.	
609
	$record=logs::record($conf);
610
	unset($conf);
611
 
612
	#如果寫log 失敗
613
	if($record["status"]==="false"){
614
 
615
		#印出訊息
616
		echo json_encode($record);
617
 
618
		#異常結束執行
619
		exit(1);
620
 
621
		}#if end
622
 
623
	#異常結束執行
624
	exit(1);
625
 
1 liveuser 626
	}#if end
627
 
183 liveuser 628
#解密參數
629
#函式說明:
630
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
631
#回傳結果:
632
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
633
#$result["function"],當前執行的函數名稱.
634
#$result["content"],加密後的結果.
635
#$result["error"],錯誤訊息陣列.
636
#$result["argu"],使用的參數.
637
#必填參數:
638
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
639
$conf["enCodeStr"]=$enCodeStr["content"];
640
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
641
$conf["enCodeType"]="qbpwcf";
642
#可省略參數:
643
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
644
#$conf["sha1Raw"]="false";
645
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
646
#$conf["p_hash"]="";
647
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
648
#$conf["keyForAes256"]="";
649
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
650
#$conf["aes256Encode"]="";
651
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
652
$conf["qbpwcfDecode"]="true";
653
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
654
#$conf["gpgDecrypt"]="true";
655
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
656
#$conf["gpgId"]="";
657
#參考資料:
658
#sha1=>http://php.net/manual/en/function.sha1.php
659
#md5=>http://php.net/manual/en/function.md5.php
660
#password_hash=>http://php.net/manual/en/function.password-hash.php
661
#password_verify=>http://php.net/manual/en/function.password-verify.php
662
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
663
#備註:
664
#無.
665
$enCodeStr=authenticate::enCodeStr($conf);
666
unset($conf);
1 liveuser 667
 
183 liveuser 668
#debug
669
#var_dump(__LINE__,$enCodeStr);exit;
1 liveuser 670
 
183 liveuser 671
#如果執行異常
672
if($enCodeStr["status"]==="false"){
673
 
674
	#函式說明:
675
	#撰寫log
676
	#回傳結果:
677
	#$result["status"],狀態,"true"或"false".
678
	#$result["error"],錯誤訊息陣列.
679
	#$result["function"],當前函式的名稱.
680
	#$result["argu"],使用的參數.
681
	#必填參數:
682
	#$conf["path"],log檔案的路徑與名稱.
683
	$conf["path"]=$logFile;
684
	#$conf["content"],字串,要寫的內容.
685
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
686
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
687
	$conf["fileArgu"]=__FILE__;
688
	#可省略參數:
689
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
690
	#$conf["rewrite"]="false";
691
	#參考資料:
692
	#無.
693
	#備註:
694
	#無.	
695
	$record=logs::record($conf);
696
	unset($conf);
697
 
698
	#如果寫log 失敗
699
	if($record["status"]==="false"){
700
 
701
		#印出訊息
702
		echo json_encode($record);
703
 
704
		#異常結束執行
705
		exit(1);
706
 
707
		}#if end
708
 
709
	#異常結束執行
710
	exit(1);
711
 
712
	}#if end
713
 
714
#取得解碼後的結果
715
$params=$enCodeStr["content"];
716
 
1 liveuser 717
#轉換為陣列
718
$params=(array)$params;
719
 
720
#函式說明:
721
#撰寫log
722
#回傳結果:
723
#$result["status"],狀態,"true"或"false".
724
#$result["error"],錯誤訊息陣列.
725
#$result["function"],當前函式的名稱.
726
#$result["argu"],使用的參數.
727
#必填參數:
728
#$conf["path"],log檔案的路徑與名稱.
729
$conf["path"]=$logFile;
730
#$conf["content"],字串,要寫的內容.
731
$conf["content"]=json_encode($params).PHP_EOL;
732
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
733
$conf["fileArgu"]=__FILE__;
734
#可省略參數:
735
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
736
#$conf["rewrite"]="false";
737
#參考資料:
738
#無.
739
#備註:
740
#無.	
741
$record=logs::record($conf);
742
unset($conf);
743
 
744
#如果寫log 失敗
745
if($record["status"]==="false"){
746
 
747
	#印出訊息
748
	echo json_encode($record);
749
 
183 liveuser 750
	#異常結束執行
751
	exit(1);
1 liveuser 752
 
753
	}#if end
754
 
755
#如果少了使用資料庫系統的dbSecret
756
if(!isset($params["dbSecret"])){
757
 
758
	#結束執行
759
	exit;
760
 
761
	}#if end
762
 
763
#驗證密碼是否正確
764
else{
765
 
766
	#若dbSecret錯誤
767
	if($params["dbSecret"]!==dbSecret){
768
 
183 liveuser 769
		#函式說明:
770
		#撰寫log
771
		#回傳結果:
772
		#$result["status"],狀態,"true"或"false".
773
		#$result["error"],錯誤訊息陣列.
774
		#$result["function"],當前函式的名稱.
775
		#$result["argu"],使用的參數.
776
		#必填參數:
777
		#$conf["path"],log檔案的路徑與名稱.
778
		$conf["path"]=$logFile;
779
		#$conf["content"],字串,要寫的內容.
780
		$conf["content"]="wrong dbSecret".PHP_EOL;
781
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
782
		$conf["fileArgu"]=__FILE__;
783
		#可省略參數:
784
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
785
		#$conf["rewrite"]="false";
786
		#參考資料:
787
		#無.
788
		#備註:
789
		#無.	
790
		$record=logs::record($conf);
791
		unset($conf);
792
 
793
		#如果寫log 失敗
794
		if($record["status"]==="false"){
795
 
796
			#印出訊息
797
			echo json_encode($record);
798
 
799
			#異常結束執行
800
			exit(1);
801
 
802
			}#if end
803
 
1 liveuser 804
		#結束執行
805
		exit;
806
 
807
		}#if end
808
 
809
	#移除傳遞的 dbSecret
810
	unset($params["dbSecret"]);
811
 
812
	}#else end
813
 
814
#檢查變數
815
#函式說明:
816
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
817
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
818
#$reuslt["error"],執行不正常結束的錯訊息陣列.
819
#$result["function"],當前執行的函式名稱.
820
#$result["argu"],設置給予的參數.
821
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
822
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
823
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
824
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
825
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
826
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
827
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
828
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
829
#必填寫的參數:
830
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
831
$conf["variableCheck::checkArguments"]["varInput"]=&$params;
832
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
833
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
834
#可以省略的參數:
835
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
836
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbUser","dbPass","dtName","cols","vals");
837
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
838
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","array","array");
839
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
840
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
841
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
842
#$conf["canNotBeEmpty"]=array();
843
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
844
#$conf["canBeEmpty"]=array();
845
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
846
#$conf["skipableVariableCanNotBeEmpty"]=array();
847
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
848
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPort");
849
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
850
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
851
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
852
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("3306");
853
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
854
#$conf["disallowAllSkipableVarIsEmpty"]="";
855
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
856
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
857
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
858
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cols","vals");
859
#參考資料來源:
860
#array_keys=>http://php.net/manual/en/function.array-keys.php
861
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
862
unset($conf["variableCheck::checkArguments"]);
863
 
864
#函式說明:
865
#撰寫log
866
#回傳結果:
867
#$result["status"],狀態,"true"或"false".
868
#$result["error"],錯誤訊息陣列.
869
#$result["function"],當前函式的名稱.
870
#$result["argu"],使用的參數.
871
#必填參數:
872
#$conf["path"],log檔案的路徑與名稱.
873
$conf["path"]=$logFile;
874
#$conf["content"],字串,要寫的內容.
875
$conf["content"]=json_encode($checkArguments).PHP_EOL;
876
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
877
$conf["fileArgu"]=__FILE__;
878
#可省略參數:
879
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
880
#$conf["rewrite"]="false";
881
#參考資料:
882
#無.
883
#備註:
884
#無.	
885
$record=logs::record($conf);
886
unset($conf);
887
 
888
#如果寫log 失敗
889
if($record["status"]==="false"){
890
 
891
	#印出訊息
892
	echo json_encode($record);
893
 
894
	#結束執行
895
	exit;
896
 
897
	}#if end
898
 
899
#如果執行失敗
900
if($checkArguments["status"]==="false"){
901
 
902
	#印出訊息
903
	echo json_encode($checkArguments);
904
 
905
	#結束執行
906
	exit;
907
 
908
	}#if end
909
 
910
#如果邊數檢查不通過
911
if($checkArguments["passed"]==="false"){
912
 
913
	#印出訊息
914
	echo json_encode($checkArguments);
915
 
916
	#結束執行
917
	exit;
918
 
919
	}#if end
920
 
183 liveuser 921
/*
922
#可能存在的參數
1 liveuser 923
$params["dbAddr"];
183 liveuser 924
$params["dbPort"];
1 liveuser 925
$params["dbName"];
926
$params["dbUser"];
927
$params["dbPass"];
928
$params["dtName"];
183 liveuser 929
$params["cols"];#條件欄位
930
$params["vals"];#條件欄位對應數值
931
*/
1 liveuser 932
 
933
#涵式說明:
934
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
935
#回傳的數值:	
936
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
937
#$result["error"],錯誤訊息.
938
#$result["sql"],執行的sql語法.
939
#$result["function"],當前執行的涵式
940
#必填的參數:
941
$conf["dbAddress"]=$params["dbAddr"];#爲mysql-Server的位置
942
$conf["dbAccount"]=$params["dbUser"];#爲用於連入mysql-Server時要使用的帳號
943
$conf["selectedDataBaseName"]=$params["dbName"];#要選取的資料庫名稱	
944
$conf["tableName"]=$params["dtName"];#爲要插入資料的資料表名稱
945
$conf["columnName"]=$params["cols"];#爲資料表的項目名稱,
946
	#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
947
$conf["insertValue"]=$params["vals"];#爲要插入度數值,
948
	#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
949
#可以省略的變數:
950
$conf["dbPassword"]=$params["dbPass"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
951
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 3306 port.
952
$conf["dbPort"]=$params["dbPort"];
953
#參考資料來源:
954
#http://www.javaworld.com.tw/jute/post/view?bid=21&id=173738&sty=1
955
$insertData=db::insertData($conf);
956
unset($conf);
957
 
183 liveuser 958
#如果執行異常
959
if($insertData["status"]==="false"){
960
 
961
	#函式說明:
962
	#撰寫log
963
	#回傳結果:
964
	#$result["status"],狀態,"true"或"false".
965
	#$result["error"],錯誤訊息陣列.
966
	#$result["function"],當前函式的名稱.
967
	#$result["argu"],使用的參數.
968
	#必填參數:
969
	#$conf["path"],log檔案的路徑與名稱.
970
	$conf["path"]=$logFile;
971
	#$conf["content"],字串,要寫的內容.
972
	$conf["content"]=json_encode($insertData).PHP_EOL;
973
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
974
	$conf["fileArgu"]=__FILE__;
975
	#可省略參數:
976
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
977
	#$conf["rewrite"]="false";
978
	#參考資料:
979
	#無.
980
	#備註:
981
	#無.	
982
	$record=logs::record($conf);
983
	unset($conf);
984
 
985
	#如果寫log 失敗
986
	if($record["status"]==="false"){
987
 
988
		#印出訊息
989
		echo json_encode($record);
990
 
991
		#異常結束執行
992
		exit(1);
993
 
994
		}#if end
995
 
996
	#異常結束執行
997
	exit(1);
998
 
999
	}#if end
1000
 
1 liveuser 1001
#函式說明:
1002
#撰寫log
1003
#回傳結果:
1004
#$result["status"],狀態,"true"或"false".
1005
#$result["error"],錯誤訊息陣列.
1006
#$result["function"],當前函式的名稱.
1007
#$result["argu"],使用的參數.
1008
#必填參數:
1009
#$conf["path"],log檔案的路徑與名稱.
1010
$conf["path"]=$logFile;
1011
#$conf["content"],字串,要寫的內容.
1012
$conf["content"]=json_encode($insertData).PHP_EOL;
1013
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1014
$conf["fileArgu"]=__FILE__;
1015
#可省略參數:
1016
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1017
#$conf["rewrite"]="false";
1018
#參考資料:
1019
#無.
1020
#備註:
1021
#無.	
1022
$record=logs::record($conf);
1023
unset($conf);
1024
 
1025
#如果寫log 失敗
1026
if($record["status"]==="false"){
1027
 
1028
	#印出訊息
1029
	echo json_encode($record);
1030
 
1031
	#結束執行
1032
	exit;
1033
 
1034
	}#if end
1035
 
1036
#印出結果
1037
echo json_encode($insertData);
1038
 
1039
?>