我寫了下面的PHP腳本來處理內容過濾的HTTP代理。代理向此腳本發佈用戶嘗試訪問的網站的URL。該腳本(顯然)檢查該網站的關鍵字應該被阻止,然後迴應代理。用這個在頁面之間導航需要很長的時間。目前....大約3分鐘。每頁。寫這個更好的方法?增速?
這裏是代碼:
<?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";
?>
爲什麼這個標記的python? – Falmarri 2010-11-18 04:25:59