Bunu yazmak için daha iyi bir yolu?

0 Cevap php

Ben içerik filtreleme için bir HTTP proxy ile çalışmak için aşağıdaki PHP komut dosyası yazdı. Proxy Bu komut kullanıcının ziyaret çalışıyor sitenin URL'sini nakleder. Betik (tabii ki), bloke edilmelidir anahtar kelimeler için siteyi denetler sonra vekil yanıt verir. Bu ile sayfalar arasında gezinmek için çok uzun sürüyor. Şu anda .... yaklaşık 3 dakika. sayfa başına.

Here is that code:

<?php

$location = $_POST['Location'];
$user = $_POST['User'];
if($location == "") {
  die("Invalid Request! Missing Parameter 1!");
}

if($user == "") {
  die("Invalid Request! Missing Parameter 2!");
}
$con = mysql_connect("MySQL Host", "USER", "PASS") or die(mysql_error());
mysql_select_db("DBName", $con) or die(mysql_error());
$query = "SELECT `Policy` FROM Subscribe WHERE `Username`='$user'";
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) == "1") {
  $nothing = "nothing";
} else {
  die("Invalid User!");
}
while($row = mysql_fetch_assoc($result)) {
  $policy = $row['Policy'];
}
if($policy == "0") {
  echo "allow";
  exit;
}
if($policy == "4") {
  $query1 = "SELECT `Address`, `Keyword` FROM Policy WHERE `Owner`='$user'";
  $result2 = mysql_query($query1) or die(mysql_error());
  while($row = mysql_fetch_assoc($result2)) {
    $address = explode(',', $row['Address']);
    $keyword = explode(',', $row['Keyword']);
  }
} else {
  $query2 = "SELECT `Address`, `Keyword` FROM Policies WHERE `Policy`='p".$policy."'";
  $result2 = mysql_query($query2) or die(mysql_error());
  while($row = mysql_fetch_assoc($result2)) {
    $address = explode(',', $row['Address']);
    $keyword = explode(',', $row['Keyword']);
  }
}

if(in_array($location, $address)) {
  echo "deny";
  exit;
} else {
  $meta = get_meta_tags($location);
  $keywords = $meta['keywords'];
  $keywords = preg_replace('/\s+/', ' ', $keywords); 
  $keywords = str_replace(' ', '', $keywords);
  $keywords = explode(',', $keywords);
  while (list($key, $val) = each($keywords)) {
    if(in_array($val, $keyword)) {
      echo "deny";
      exit;
    }
  }
  $urlk = explode('.', $location);
  while (list($key, $val) = each($urlk)) {
    if(in_array($val, $keyword)) {
      echo "deny";
      exit;
    }
  }
}
echo "allow";
?>

0 Cevap