strpos无法正常运行?

时间:2019-03-01 02:01:21

标签: php

我在这里有一些代码,应该执行的操作是查看某人是否在黑名单文件中,但是无论他们在黑名单文件中是否每次都说“全部”有帮助吗?

<?php
// if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {echo('\nMSIE');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE){echo('\nTrident');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE){echo('\nFirefox');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE){echo('\nChrome');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== FALSE){echo('\nOpera Mini');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE){echo('\nOpera');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE){echo('\nSafari');}
//  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla') !== FALSE){echo('\nMozilla');}
//  else {

// error_reporting(0);

$Username = $_GET['userdatafind'];
if(!$Username){
  echo'No ID Provided';
}
  $file = './users.txt';
$searchfor = $Username;
  
  $contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";

$daa = strtolower("DISCORDID=".$Username);
$WHITELIST = file_get_contents('./blacklist.txt');
$content = strtolower($WHITELIST);
echo($daa);

if(strpos($content, $daa) !== false){
if(preg_match_all($pattern, $contents, $matches)){
// $matches[0]
  
  $datato = implode($matches[0]);
    
  $yeet = file_get_contents($file);
$new = str_replace($datato, 'RIP User Blacklisted.', $yeet);
file_put_contents($_SERVER['DOCUMENT_ROOT']."/users.txt", $new);
  file_put_contents($_SERVER['DOCUMENT_ROOT']."/blacklist.txt", $datato);
  echo'done';
}else{
  $newdata = "USERNAME=LOLBOTBLACKLIST DISCORDID=".$Username;
  
  file_put_contents($_SERVER['DOCUMENT_ROOT']."/blacklist.txt", "\n".$newdata, FILE_APPEND | LOCK_EX);
  
echo'done';
}
}else{
  echo'all';
}

// }
?>

老实说,我不知道解决方案。

1 个答案:

答案 0 :(得分:-1)

是的,所以我找到了一个解决方案,以下是对我有用的:

 <?php

   $Username = $_GET['userdatafind'];
   if(!$Username){
   echo'No ID Provided';
   }
   $file = './users.txt';
   $searchfor = $Username;

   $contents = file_get_contents($file);
   $pattern = preg_quote($searchfor, '/');
   $pattern = "/^.*$pattern.*\$/m";

   $daa = strtolower("DISCORDID=".$Username);
   $WHITELIST = file_get_contents('./blacklist.txt');
   $content = strtolower($WHITELIST);
   if(strpos($content, $daa)){
   echo'all';
   }else{
   if(preg_match_all($pattern, $contents, $matches)){
   // $matches[0]

   $datato = implode($matches[0]);

   $yeet = file_get_contents($file);
   $new = str_replace($datato, 'RIP User Blacklisted.', $yeet);
   file_put_contents($_SERVER['DOCUMENT_ROOT']."/users.txt", $new);
   file_put_contents($_SERVER['DOCUMENT_ROOT']."/blacklist.txt", $datato);
   echo'done';
   }else{
   $newdata = "USERNAME=LOLBOTBLACKLIST DISCORDID=".$Username;

   file_put_contents($_SERVER['DOCUMENT_ROOT']."/blacklist.txt", "\n".$newdata, 
   FILE_APPEND | LOCK_EX);

   echo'done';
   }
   }

   // }
   ?>