Last active
August 29, 2015 13:57
-
-
Save Inndy/9657527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DEBUG', false); | |
if (DEBUG) { | |
error_reporting(E_ALL ^ E_NOTICE); | |
} else { | |
error_reporting(0); | |
} | |
// ob_start(); // Start buffering | |
define('DB_HOST', 'localhost'); | |
define('DB_USER', 'dbuser'); | |
define('DB_PASS', 'dbpass'); | |
define('DB_NAME', 'dbname'); | |
$conn = mysql_pconnect(DB_HOST, DB_USER, DB_PASS); | |
mysql_select_db(DB_NAME, $conn); | |
mysql_query("SET NAMES 'utf8'"); | |
function ipv4_to_int($ip) { | |
if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\$/", $ip) !== false) { | |
$ip = array_map(intval, explode(".", $ip)); | |
return ($ip[0] << 24) | ($ip[1] << 16) | ($ip[2] << 8) | $ip[3]; | |
} else { | |
return -1; | |
} | |
} | |
function ip_filter($ip, $loc, $mask = 32) { | |
if ($mask < 0 || $mask > 32) | |
return false; | |
list($ip, $loc) = array_map(ipv4_to_int, array($ip, $loc)); | |
$mask = (-1) >> (32 - $mask) << (32 - $mask); | |
return ($ip & $mask) == ($loc & $mask); | |
} | |
function detect_ip($lock_in, $mask = 32) { | |
$ip = $_SERVER['REMOTE_ADDR']; | |
return ip_filter($ip, $lock_in, $mask); | |
} | |
function recursive_map(&$var, $func) { | |
foreach ($var as $k => $v) { | |
if (gettype($v) == "array") { | |
$var[$k] = recursive_map($v, $func); | |
} else { | |
$var[$k] = $func($v); | |
} | |
} | |
return $var; | |
} | |
if (get_magic_quotes_gpc()) recursive_map($_POST, stripslashes); | |
recursive_map($_POST, mysql_real_escape_string); | |
recursive_map($_GET, mysql_real_escape_string); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment