-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
30 lines (22 loc) · 826 Bytes
/
lib.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
<?php
define('ESCAPE_PATTERN', '/(and|or).*(union|select|insert|update|delete|from|where|limit|create|drop).*/i');
define('ESCAPE_REPLACE', '');
function sql_escape_string($str)
{
if(defined('ESCAPE_PATTERN') && defined('ESCAPE_REPLACE')) {
$pattern = ESCAPE_PATTERN;
$replace = ESCAPE_REPLACE;
if($pattern)
$str = preg_replace($pattern, $replace, $str);
}
$str = call_user_func('addslashes', $str);
return $str;
}
function get_real_client_ip()
{
$real_ip = $_SERVER['REMOTE_ADDR'];
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_SERVER['HTTP_X_FORWARDED_FOR']) ){
$real_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return preg_replace('/[^0-9.]/', '', $real_ip);
}