10000){ $out.= $row['text']; if(1==2){ // switch on to 'keep' any record that ever was accessed $sql = "UPDATE $avpos_table" . ' SET keep = 1' . ' WHERE webkey = ' . StrSQL($given_webkey); $result = mysqli_query($link,$sql) or email_death("ERR05: " . mysqli_error($link)); } // delete all entries older than 10 minutes that are not flagged keep $sql = "DELETE FROM $avpos_table" . ' WHERE timestamp < DATE_SUB(NOW(), INTERVAL 10 MINUTE)' . ' AND keep = 0'; $result = mysqli_query($link,$sql) or email_death("ERR06: " . mysqli_error($link)); } else{ $out.="Data was incomplete, please try again.\n\nThis feature is new and experimental - you're welcome to report any issues."; } } echo $out; } else{ header('HTTP/1.0 400 Bad Request'); die("400 Bad Request: No valid action specified."); } function undo_magic_quotes(&$var) { // Does anyone still use these? Probably not but just in case. if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { // This doesn't remove the slashes in the keys, but that doesn't matter for us. foreach ($var as $k => &$v) { if (is_array($v)) undo_magic_quotes($v); else $v = stripslashes($v); } } } function IdentSQL($str){ return '`' . str_replace('`', '``', $str) . '`'; } function StrSQL($str){ if ($str === null) return "NULL"; return "'" . mysqli_real_escape_string($GLOBALS['link'], strval($str)) . "'"; } function IntSQL($int){ return strval(intval($int)); } function isValidGuid($guid){ return !empty($guid) && preg_match('/^\{?[a-zA-Z0-9]{8}(?:-[a-zA-Z0-9]{4}){4}[a-zA-Z0-9]{8}\}?$/', $guid); } function email_death($error){ $body="\n"; $body.="\n\$_SERVER\n"; foreach($_SERVER as $key_name => $key_value) { $body.= $key_name . " = " . $key_value . "\n"; } $body.="\n\$_GET\n"; foreach($_GET as $key_name => $key_value) { $body.= $key_name . " = " . $key_value . "\n"; } $body.="\n\$_POST\n"; foreach($_POST as $key_name => $key_value) { $body.= $key_name . " = " . $key_value . "\n"; } $to = $GLOBALS['email_to']; $subject = "avsitter: $error"; $email_headers = "From: ". $GLOBALS['email_from'] ."\r\n" . "X-Mailer: php"; mail($to, $subject, $body, $email_headers); die($error); } function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } function endsWith($haystack, $needle) { // search forward starting from end minus needle length characters return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); } function isAllowedIP($ip){ if($GLOBALS['check_ip']==false){ return true; } $llsubnets = array( "8.2.32.0/22", "8.4.128.0/22", "8.10.144.0/21", "63.210.156.0/22", "64.154.220.0/22", "216.82.0.0/18" ); foreach($llsubnets as $range){ if(ip_in_range($ip,$range)) return true; } return false; } // check if an ip_address in a particular range function ip_in_range( $ip, $range ) { // $range is in IP/CIDR format eg 127.0.0.1/24 list( $range, $netmask ) = explode( '/', $range, 2 ); $range_decimal = ip2long( $range ); $ip_decimal = ip2long( $ip ); $wildcard_decimal = pow( 2, ( 32 - $netmask ) ) - 1; $netmask_decimal = ~ $wildcard_decimal; return ( ( $ip_decimal & $netmask_decimal ) == ( $range_decimal & $netmask_decimal ) ); }