PHP Arrays (in_array)

Soldato
Joined
27 Dec 2005
Posts
17,316
Location
Bristol
I'm trying to do an in_array on a database array. Code:

Code:
$sqlips = mysql_query("SELECT * FROM blockedips");
$ips = mysql_fetch_array($sqlips);
if (in_array ($_SERVER['REMOTE_ADDR'], $ips)) {
exit();
} else {
......

and I'm getting the error;

Warning: in_array() [function.in-array]: Wrong datatype for second argument in xxxxxx/log.php on line 4

I've tried using the in_array straight on $sqlips as well and get the same error. Any ideas?
 
I think/hope so, I guess there's no way of me checking as I'm not a blocked IP.

Maybe you could advise an alternative piece of code? Basically I have a log system which logs visitors to my site and the order in which they view pages. Through this I've now created the option to delete all records with a certain IP as well as blocking that IP from being logged by the tracker (but not viewing the site).

So when I delete a row, it also adds the IP address to a db named blockedips. My log file then does the above before processing a visitor and entering them into the log db. So basically I've got a db with IP's and their unique ID's which I want to try and match to the users IP address. If there's a match to any one of the records, then script won't run.
 
Good idea with the num_rows, works a treat and like you says saves querying the entire database (even though it's not that big).

I'm not too worried about bad ip's becoming good ip's as there's no difference to what the end user can see or do, it simply limits what traffic gets logged by a visitor tracker I've made. It's pretty easy to tell what are bots and what are not (ie. a visitor that can't store sessions and visits a different page every 2 seconds). Was getting annoying filtering through all these to see the real people so now I've added a function which deletes all entries with a specific IP and also adds that IP it to the blocked db.
 
Similar to what I'm using now... but more understandable to me :p

Code:
$ip = $_SERVER['REMOTE_ADDR'];

$sqlips = mysql_query("SELECT * FROM blockedips WHERE ip='$ip'");
$checkips = mysql_num_rows($sqlips);
if($checkips < 1){
...... // log etc
 
Back
Top Bottom