/var/www/hkosl.com/chineseaaedu/webadmin/check_login.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

    
if (session_id() === "") {
        
session_start();
    }
    
//---------------------------------MYSQL輸入-----------------------------------------//
    
function pass_gen($length 8) {
        
$pass = array();
        
$a = array('a','s','d','f','g','h','j','k','l','b');
        
$b = array('1','2','3','4','5','6','7','8','9','0');
        for (
$i 0$i $length$i++) {
            
$r1 rand(0,9);
            
$r2 rand(0,1);
            
$r3 rand(0,1);
            if(
$r2==1){
                
$string $b[$r1];
            }else{
                
$string $a[$r1];
            }
            if(
$r3==1){
                
$string strtoupper($string);
            }
            
$pass[] = $string;
        }
        return 
implode($pass);
    }
    function 
getPhpTemplate$file ''$data = array() ) {
        if (!
file_exists($file)||!is_array($data)) return false;
        
$template file_get_contents($file);
        foreach (
$data as $key=>$value$template str_replace('#{'.$key.'}'$value$template);
        return 
$template;
    }
    function 
formatPostData$datas = array(), $filter = array(), $kill_empty false ) {    
        if (
count($datas)<1) return $datas;
        
$main_keys array_keys($datas[current(array_keys($datas))]);
        
$sub_keys array_keys($datas);
        foreach(
$main_keys as $main_key) {
            
$empty true;
            foreach(
$sub_keys as $sub_key) {
                
$data[$main_key][$sub_key] = $datas[$sub_key][$main_key];
                
$empty = !empty($data[$main_key][$sub_key])&&!in_array($sub_key$filter) ? false $empty;
            }
            if (
$kill_empty && $emptyarray_pop($data);
        }
        return 
$data;
    }
    function 
getJsTemplate$file '' ) {
        if (!
file_exists($file)) return false;
        
$template file_get_contents($file);
        
$template str_replace("\n"""str_replace("'""\'"$template));
        
$template str_replace("\r"""$template);
        for (
$i=0$i<10$i++) $template str_replace("  "" "$template);
        
$template str_replace("> <""><"$template);
        return 
$template;
    }
    function 
replaceJsTemplate$html ) {
        if (!
$html) return false;
        
$template $html;
        
$template str_replace("\n"""str_replace("'""\'"$template));
        
$template str_replace("\r"""$template);
        for (
$i=0$i<10$i++) $template str_replace("  "" "$template);
        
$template str_replace("> <""><"$template);
        return 
$template;
    }
    function 
mysql_install($array,$table,$action='add',$idname="",$id=""){ //array字串(array_keys),db table name,add=新db edit=修改,del= 刪除
        
$arraykey=array_keys($array);
        if(
$action=='add'){
        
$sql"INSERT INTO `".$table."` (";
        for(
$i=0;$i<count($array);$i++){
            if(
$i+1<count($array)){
                
$dot=',';
            }else{
                
$dot='';
            }
            
$sql.= "`".$arraykey[$i]."`".$dot;
        }
        
$sql.= ') values (';
        for(
$i=0;$i<count($array);$i++){
            if(
$i+1<count($array)){
                
$dot=',';
            }else{
                
$dot='';
            }
            
//$sql.= "'".$array[$arraykey[$i]]."'".$dot;
            
$sql.= "?".$dot;
        }
        
$sql.= ')';
        }else if(
$action=='edit'){
            
$sql="UPDATE `".$table."` SET "
            for(
$i=0;$i<count($array);$i++){
                if(
$i+1<count($array)){
                    
$dot=',';
                }else{
                    
$dot='';
                }
                
//$sql.= "`".$arraykey[$i]."` = '".$array[$arraykey[$i]]."'".$dot;
                
$sql.= "`".$arraykey[$i]."` = ?".$dot;
            }
            
//$sql.=" WHERE `".$table."`.`".$idname."` =".$id.";";
            
$sql.=" WHERE `".$table."`.`".$idname."` =?;";
        }else if(
$action=='del'){
            
$sql.="DELETE FROM `".$table."` WHERE `".$table."`.`".$idname."` =".$id;
        }
        return 
$sql;
    }
    
// Check if the user is logged in
    
if (!isset($_SESSION['loginname'])) {
        
header("Location: ".'http://'.$_SERVER['HTTP_HOST'].'/chineseaaedu/webadmin/'."login.php");
        exit;
    }
    include_once (
'configure.php');
?>