below is my completed code, please somebody can help me how to accept ONLY agents pasted in $ar_agent $ar_badreferer , all others agents and referers must be disabled, being more clear,, the code below currently disable agents/referers access only as desrcibed in $ar_agent $ar_badreferer. require_once('Connections/default.php'); // Set These VARS $banned_ips = file_get_contents("./ipjatba.txt"); $logfile = "./log.html"; $ipfile = "./ajpijat.txt"; $ar_agent = array("Firefox","Opera"); $ar_badreferer = array("Google","Yahoo"); $doubles = 0; // value of 0 or 1 $userid = "admin"; // Change this to the userid in your database if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_default, $default); $query_Recordset1 = "SELECT * FROM sajti WHERE (userid = 'admin') AND (sajti.a_count < sajti.a_max) AND (sajti.a_active = '1') ORDER BY sajti.a_count"; $Recordset1 = mysql_query($query_Recordset1, $default) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); // Fixed Vars - Do NOT EDIT $display = 1; $reason = ""; // Function HTTP_USER_AGENTS function checkagent($agent) { if (substr_count($_SERVER['HTTP_USER_AGENT'], $agent) <> 0) { $bagent = 1; } return $bagent; } // Function HTTP_REFERER function checkref($referer) { if(substr_count($_SERVER['HTTP_REFERER'], $referer) <> 0) { $breferer = 1; } return $breferer; } function itsnull($danullvoid) { if ($danullvoid == "") { return false; } return true; } $ar_banned = explode("\n", $banned_ips); $enduserip = $_SERVER['REMOTE_ADDR']; list($eu_a, $eu_b, $eu_c, $eu_d) = split("\.", $enduserip); foreach ($ar_banned as $val) { list($banned_a, $banned_b, $banned_c, $banned_d) = split("\.", $val); if (($eu_a == $banned_a) AND ($eu_b == $banned_b) AND ($val <> "")){ $reason .= "Banned IP (" . $val . ") / "; // print "val=".$val; } } if ($doubles == 1) { $fs = file_get_contents($ipfile); $fa = explode("\n", $fs); foreach ($fa as $value) { if ($value == $_SERVER['REMOTE_ADDR']) { $reason .= "Already / "; } } } // Filter HTTP_USER_AGENT foreach ($ar_agent as $agent_value) { if (checkagent($agent_value) == 1) { $display = 0; $reason .= "Bad Agent: ". $agent_value ." / "; } } // Filter HTTP_REFERER foreach ($ar_badreferer as $badreferer_value) { if (checkref($badreferer_value) == 1) { $display = 0; $reason .= "Bad Referer: ". $badreferer_value ." / "; } } $calc_ctr = rand(1,100); if ($reason == "") { $display = 1; $foundone = 0; do { if ($calc_ctr < $row_Recordset1['a_ctr']) { $foundone = 1; echo "display=1&banner=" . $row_Recordset1['a_url']; $fh = fopen($logfile, 'a') or die("can't open file"); fwrite($fh,"\n<br>Referer: "); fwrite($fh, ($_SERVER['HTTP_REFERER']) ); fwrite($fh,", "); fwrite($fh, ($_SERVER['HTTP_USER_AGENT']) ); fwrite($fh,", "); fwrite($fh, $_SERVER['REMOTE_ADDR']); fwrite($fh,", "); fwrite($fh, date('l jS \of F Y h:i:s A') ); fclose($fh); if ($doubles == 1) { $ipf = fopen($ipfile, 'a') or die("Can't Open File"); fwrite($ipf, $_SERVER['REMOTE_ADDR']); fwrite($ipf, "\n"); fclose($ipf); } $newcount = $row_Recordset1['a_count']; $newcount++; $updateSQL = sprintf("UPDATE sajti SET a_count=%s WHERE affiliateid=%s", GetSQLValueString($newcount, "int"), GetSQLValueString($row_Recordset1['affiliateid'], "int")); mysql_select_db($database_default, $default); $Result1 = mysql_query($updateSQL, $default) or die(mysql_error()); } } while ( ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) && ($foundone == 0)); if ($foundone == 0) { echo "display=0&banner="; } } else { //echo "display=0&ctr=". $ctr . "&banner=" . $arr_affiliate[$affiliate_id]; echo "display=0&banner="; $fh = fopen($logfile, 'a') or die("can't open file"); fwrite($fh,"\n<font color=\"red\"><br><b>" . $reason); fwrite($fh,"</b> "); fwrite($fh,"Referer: "); fwrite($fh, ($_SERVER['HTTP_REFERER']) ); fwrite($fh,", "); fwrite($fh, ($_SERVER['HTTP_USER_AGENT']) ); fwrite($fh,", "); fwrite($fh, $_SERVER['REMOTE_ADDR']); fwrite($fh,", "); fwrite($fh, date('l jS \of F Y h:i:s A') ); fwrite($fh, "</font>"); fclose($fh); } mysql_free_result($Recordset1); Code (markup):