Subversion Repositories php-qbpwcf

Rev

Rev 170 | Rev 182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 170 Rev 179
Line 458... Line 458...
458
				#回傳結果
458
				#回傳結果
459
				return $result;
459
				return $result;
460
				
460
				
461
				}#if end
461
				}#if end
462
 
462
 
463
			}#if end	
463
			}#if end
464
			
464
			
465
		#執行到這邊代表正常
465
		#執行到這邊代表正常
466
		#設置執行正常
466
		#設置執行正常
467
		$result["status"]="true";
467
		$result["status"]="true";
468
		
468
		
Line 471... Line 471...
471
 
471
 
472
		}#函式結束
472
		}#函式結束
473
 
473
 
474
	/*
474
	/*
475
	#函式說明:
475
	#函式說明:
-
 
476
	#用來檢查指定 session 變數是否存在以及其值是否正確,如果檢查不通過,可進行轉址.
-
 
477
	#回傳結果:
-
 
478
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
-
 
479
	#$result["function"],當前執行的函數名稱.
-
 
480
	#必填參數:
-
 
481
	#$conf["key"],字串陣列,session的key名稱與層級.
-
 
482
	$conf["key"]=array();
-
 
483
	#$conf["content"],session的內容應該要等於什麼才是對的.
-
 
484
	$conf["content"]=;
-
 
485
	#$conf["failLocation"],當驗證失敗時要轉址到的位置.
-
 
486
	$conf["failLocation"]="";
-
 
487
	#可省略參數:
-
 
488
	#$conf["unsetSess"],字串,預設為"false",代表不需要清除檢查過的seession變數;反之為"true".
-
 
489
	#$conf["unsetSess"]="false";
-
 
490
	#參考資料:
-
 
491
	#無.
-
 
492
	#備註:
-
 
493
	#無.
-
 
494
	*/	
-
 
495
	public static function validateSession(&$conf){
-
 
496
	
-
 
497
		#初始化要回傳的變數
-
 
498
		$result=array();
-
 
499
		
-
 
500
		#記錄當前執行的函數名稱
-
 
501
		$result["function"]=__FUNCTION__;
-
 
502
	
-
 
503
		#如果 $conf 不為陣列
-
 
504
		if(gettype($conf)!="array"){
-
 
505
			
-
 
506
			#設置執行失敗
-
 
507
			$result["status"]="false";
-
 
508
			
-
 
509
			#設置執行錯誤訊息
-
 
510
			$result["error"][]="\$conf變數須為陣列形態";
-
 
511
 
-
 
512
			#如果傳入的參數為 null
-
 
513
			if($conf==null){
-
 
514
				
-
 
515
				#設置執行錯誤訊息
-
 
516
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
517
				
-
 
518
				}#if end
-
 
519
 
-
 
520
			#回傳結果
-
 
521
			return $result;
-
 
522
			
-
 
523
			}#if end
-
 
524
	
-
 
525
		#檢查參數
-
 
526
		#函式說明:
-
 
527
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
-
 
528
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
529
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
530
		#$result["function"],當前執行的函式名稱.
-
 
531
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
532
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
533
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
534
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
535
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
536
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
537
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
538
		#必填參數:
-
 
539
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
540
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
541
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
542
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","content","failLocation");
-
 
543
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
-
 
544
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
-
 
545
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
546
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
547
		#可以省略的參數:
-
 
548
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
-
 
549
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
550
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
551
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("unsetSess");
-
 
552
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
-
 
553
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
-
 
554
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
555
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
-
 
556
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
557
		#$conf["arrayCountEqualCheck"][]=array();
-
 
558
		#參考資料來源:
-
 
559
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
560
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
561
		unset($conf["variableCheck::checkArguments"]);
-
 
562
	
-
 
563
		#如果檢查失敗
-
 
564
		if($checkResult["status"]==="false"){
-
 
565
			
-
 
566
			#設置執行失敗
-
 
567
			$result["status"]="false";
-
 
568
			
-
 
569
			#設置執行錯誤訊息
-
 
570
			$result["error"]=$checkResult;
-
 
571
 
-
 
572
			#回傳結果
-
 
573
			return $result;
-
 
574
			
-
 
575
			}#if end
-
 
576
			
-
 
577
		#如果檢查不通過
-
 
578
		if($checkResult["passed"]==="false"){
-
 
579
			
-
 
580
			#設置執行失敗
-
 
581
			$result["status"]="false";
-
 
582
			
-
 
583
			#設置執行錯誤訊息
-
 
584
			$result["error"]=$checkResult;
-
 
585
 
-
 
586
			#回傳結果
-
 
587
			return $result;
-
 
588
			
-
 
589
			}#if end
-
 
590
			
-
 
591
		#函式說明:
-
 
592
		#取得指定的session數值 
-
 
593
		#回傳結果:
-
 
594
		#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
-
 
595
		#$result["error"],錯誤訊息.
-
 
596
		#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
-
 
597
		#$result["content"],session變數的內容
-
 
598
		#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
-
 
599
		#$result["function"],當前執行的函數名稱.
-
 
600
		#$result["argu"],使用的參數.
-
 
601
		#必填參數:
-
 
602
		#$conf["key"],字串陣列,session的key名稱與層級.
-
 
603
		$conf["session::getVal"]["key"]=$conf["key"];
-
 
604
		#可省略參數:
-
 
605
		#$conf["unsetSess"],字串,是否要於成功取得session變數後,將之移除,預設為"false"代表不移除;反之為"true".
-
 
606
		$conf["session::getVal"]["unsetSess"]=$conf["unsetSess"];
-
 
607
		#參考資料:
-
 
608
		#無.
-
 
609
		#備註:
-
 
610
		#無.
-
 
611
		$getVal=session::getVal($conf["session::getVal"]);
-
 
612
		unset($conf["session::getVal"]);
-
 
613
	
-
 
614
		#如果執行異常
-
 
615
		if($getVal["status"]=="false"){
-
 
616
			
-
 
617
			#設置執行失敗
-
 
618
			$result["status"]="false";
-
 
619
			
-
 
620
			#設置執行錯誤訊息
-
 
621
			$result["error"]=$getVal;
-
 
622
 
-
 
623
			#回傳結果
-
 
624
			return $result;
-
 
625
			
-
 
626
			}#if end
-
 
627
			
-
 
628
		#如果指定的session變數不存在 或 session 內容不一樣
-
 
629
		if($getVal["founded"]==="false" || $getVal["content"]!==$conf["content"]){
-
 
630
			
-
 
631
			#函式說明:
-
 
632
			#設定session變數後,立即轉址.
-
 
633
			#回傳的結果:
-
 
634
			#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
-
 
635
			#$result["function"],當前執行的函數名稱.
-
 
636
			#$result["error"],錯誤訊息陣列.
-
 
637
			#必填參數:
-
 
638
			#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
-
 
639
			$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
-
 
640
			#可省略參數:
-
 
641
			#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
-
 
642
			#$conf["sessionName"]=array("");
-
 
643
			#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
-
 
644
			#$conf["sessionValue"]=array("");
-
 
645
			#參考資料:
-
 
646
			#http://php.net/manual/en/reserved.variables.server.php
-
 
647
			#備註:
-
 
648
			#無.
-
 
649
			$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
-
 
650
			unset($conf["header::redirectionNow"]);
-
 
651
			
-
 
652
			#如果執行異常
-
 
653
			if($redirectionNow["status"]=="false"){
-
 
654
				
-
 
655
				#設置執行失敗
-
 
656
				$result["status"]="false";
-
 
657
				
-
 
658
				#設置執行錯誤訊息
-
 
659
				$result["error"]=$redirectionNow;
-
 
660
 
-
 
661
				#回傳結果
-
 
662
				return $result;
-
 
663
				
-
 
664
				}#if end
-
 
665
			
-
 
666
			}#if end
-
 
667
		
-
 
668
		}#function validateSession end
-
 
669
 
-
 
670
	/*
-
 
671
	#函式說明:
476
	#檢查session裏面的使用者$_SESSION["account"]是否在會員清單裏面,與該會員所屬的羣組是否具有權限瀏覽該子功能頁面.
672
	#檢查session裏面的使用者$_SESSION["account"]是否在會員清單裏面,與該會員所屬的羣組是否具有權限瀏覽該子功能頁面.
477
	#回傳的參數:
673
	#回傳的參數:
478
	#$result["status"],執行是否正常的識別,"true"代表一切正常,"false"代表不正常
674
	#$result["status"],執行是否正常的識別,"true"代表一切正常,"false"代表不正常
479
	#$result["error"],錯誤訊息
675
	#$result["error"],錯誤訊息
480
	#$result["function"],當前執行的函數名稱
676
	#$result["function"],當前執行的函數名稱