/var/www/hkosl.com/tracking/_functions.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
<?php


    
if (!function_exists('bind_pdo')) {
        function 
bind_pdo($sql$parameters NULL$action NULL)
        {
            global 
$dbh;

            if (
$action == "insert" || $action == "update" || $action == "delete" || empty($action)) {
                if (!(
$sth $dbh->prepare($sql))) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }

                if (!
$sth->execute($parameters)) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }
            }

            if (
$action == "selectone") {
                if (!(
$sth $dbh->prepare($sql))) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }

                if (!
$sth->execute($parameters)) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }

                
$result $sth->fetch(PDO::FETCH_ASSOC);
                if (!empty(
$result)) {
                    foreach (
$result as $key => $row) {
                        
$result[$key] = htmlspecialchars_decode($result[$key]);
                    }
                }
                return 
$result;

            }

            if (
$action == "selectall") {
                if (!(
$sth $dbh->prepare($sql))) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }

                if (!
$sth->execute($parameters)) {
                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                }

                
$result $sth->fetchAll(PDO::FETCH_ASSOC);
                if (!empty(
$result)) {
                    foreach (
$result as $key => $row) {
                        foreach (
$row as $key2 => $row2) {
                            
$result[$key][$key2] = htmlspecialchars_decode($result[$key][$key2]);
                        }
                    }
                }
                return 
$result;
            }

            if (
$action == "dump") {
                return 
dump_sql($sql$parameters);
            }

        }
    }


    if (!
function_exists('dump_sql')) {
        function 
dump_sql($sql$parameters)
        {
            
$keys = array();

            
# build a regular expression for each parameter
            
foreach ($parameters as $key => $value) {
                if (
is_string($key)) {
                    
$keys[] = '/:' $key '/';
                } else {
                    
$keys[] = '/[?]/';
                }
            }

            foreach (
$parameters as $key2 => $value) {
                
$parameters[$key2] = "'" $value "'";
            }

            
$sql preg_replace($keys$parameters$sql1$count);

            
#trigger_error('replaced '.$count.' keys');

            
return $sql;
        }
    }

function 
getRealIpAddr() {
    if ( !empty( 
$_SERVER['HTTP_CLIENT_IP'] ) )   //check ip from share internet
        
{
        return 
$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif ( !empty( 
$_SERVER['HTTP_X_FORWARDED_FOR'] ) )   //to check ip is pass from proxy
        
{
        return 
$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else {
        return 
$_SERVER['REMOTE_ADDR'];
    }
    return 
0;
}