]> git.mxchange.org Git - ctracker.git/blob - libs/lib_general.php
b3db3ef3d75bbc72dbfb6e73f74d2c388db0fab0
[ctracker.git] / libs / lib_general.php
1 <?php
2 /**
3  * General functions library
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             3.0.0
7  * @copyright   Copyright (c) 2009 Cracker Tracker Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24
25 if (!function_exists('implode_r')) {
26         // Implode recursive a multi-dimension array, taken from www.php.net
27         function implode_r ($glue, $array, $array_name = NULL) {
28                 $return = array();
29                 while(list($key,$value) = @each($array)) {
30                         if(is_array($value)) {
31                                 // Is an array again, so call recursive
32                                 $return[] = implode_r($glue, $value, (string) $key);
33                         } else {
34                                 if($array_name != NULL) {
35                                         $return[] = $array_name . '[' . (string) $key . ']=' . $value . "\n";
36                                 } else {
37                                         $return[] = $key . '=' . $value."\n";
38                                 }
39                         }
40                 } // END - while
41
42                 // Return resulting array
43                 return(implode($glue, $return));
44         } // END - function
45 } // END - if
46
47 if (!function_exists('implode_secure')) {
48         // Implode a simple array with a 'call-back' to our escaper function
49         function implode_secure ($array) {
50                 // Return string
51                 $return = '';
52
53                 // Implode all data
54                 foreach ($array as $entry) {
55                         // Don't escape some
56                         if (in_array($entry, array('NOW()'))) {
57                                 // Add it with non-string glue
58                                 $return .= $entry . ',';
59                         } elseif (empty($entry)) {
60                                 // Empty strings need no escaping
61                                 $return .= '"",';
62                         } else {
63                                 // Secure this string and add it
64                                 $return .= '"' . crackerTrackerEscapeString($entry) . '",';
65                         }
66                 } // END - foreach
67
68                 // Remove last char
69                 $return = substr($return, 0, -1);
70
71                 // Return this string
72                 return $return;
73         } // END - function
74 } // END - if
75
76 // Getter for ctracker_debug
77 function isCrackerTrackerDebug () {
78         // Is it set?
79         return ((isset($GLOBALS['ctracker_debug'])) && ($GLOBALS['ctracker_debug'] === true));
80 }
81
82 // Determines the real remote address
83 function determineRealRemoteAddress () {
84         // Is a proxy in use?
85         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
86                 // Proxy was used
87                 $address = $_SERVER['HTTP_X_FORWARDED_FOR'];
88         } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
89                 // Yet, another proxy
90                 $address = $_SERVER['HTTP_CLIENT_IP'];
91         } else {
92                 // The regular address when no proxy was used
93                 $address = $_SERVER['REMOTE_ADDR'];
94         }
95
96         // This strips out the real address from proxy output
97         if (strstr($address, ',')) {
98                 $addressArray = explode(',', $address);
99                 $address = $addressArray[0];
100         } // END - if
101
102         // Return the result
103         return $address;
104 }
105
106 // Determine if a proxy was used
107 function isProxyUsed () {
108         // Check if specific entries are set
109         $proxyUsed = ((isset($_SERVER['HTTP_X_FORWARDED_FOR'])) || (isset($_SERVER['HTTP_CLIENT_IP'])));
110
111         // Return result
112         return $proxyUsed;
113 }
114
115 // [EOF]
116 ?>