4 Replies - 614 Views - Last Post: 12 March 2014 - 10:20 AM Rate Topic: -----

#1 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 35
  • View blog
  • Posts: 877
  • Joined: 06-July 13

Warning: strpos() [function.strpos]: needle is not a string or an inte

Posted 12 March 2014 - 09:09 AM

Quote

Warning: strpos() [function.strpos]: needle is not a string or an integer in /home/directories/counter.php on line 38


??

I'm still having trouble with bots; no matter how many I stop from being logged, more new ones come on each day. I'm really sick of it. They must be at least 3/4 of my visitors and it's annoying always logging bots. Since I don't actually delete any info from the database and it's constantly keeping old entries there, it's just using up unnecessary space.

Here is my code:

$nolog = array('157.55.33.20', '66.249.75.132', '66.249.75.238', '66.249.75.51', '66.249.75.29', '66.249.73.93', '157.56.93.153', '157.55.34.74', '66.249.73.112', '157.55.32.147', '66.249.73.163', '157.55.34.171', '157.55.33.106', '5.255.253.19', '173.208.150.250', '157.56.93.41', '66.249.75.93', '66.249.81.5', '66.249.81.41', '66.249.81.13', '66.249.81.61', '72.14.199.51', '72.14.199.29', '72.14.199.238', '46.4.73.108', '66.249.85.154', '72.14.199.132', '66.249.73.187', '66.249.73.154', '204.236.235.245', '185.28.23.25', '157.56.92.158', '157.55.35.49', '5.10.83.72', '173.208.183.50', '199.30.20.18', '180.76.5.149', '180.76.5.190', '5.10.83.8', '157.55.36.54', '180.76.6.225', '180.76.5.176', '65.55.24.220', '66.249.83.85', '66.249.83.136', '180.76.5.71', '66.249.83.207', '66.249.83.39', '66.249.83.117', '66.249.83.51', '66.249.83.132', '66.249.83.238', '5.10.83.24', '89.145.95.2', '46.236.24.48', '5.10.83.34', '180.76.5.23', '180.76.5.145', '77.75.77.32', '37.140.141.10', '5.10.83.95', '5.10.83.55', '66.249.77.153', '66.249.77.238', '180.76.6.144', '66.249.83.89', '83.149.126.98', '180.76.5.194', '180.76.5.58', '180.76.6.52', '180.76.5.22', '180.76.5.25', '66.249.66.117', '180.76.5.22', '180.76.5.25', '180.76.6.156', '180.76.5.167', '157.55.35.52', '5.10.83.11', '157.55.32.97', '157.55.32.97', '180.76.6.146', '66.249.66.89', '180.76.6.231', '157.55.33.248', '180.76.6.40', '180.76.5.148', '157.56.93.52', '199.30.20.58', '66.249.66.238', '66.249.66.132', '66.249.66.51', '66.249.74.99', '66.249.77.175', '5.10.83.58', '157.56.92.159', '66.249.74.29', '66.249.74.168', '66.249.74.170', '162.210.196.130', '180.76.6.16', '180.76.6.53', '199.30.26.221', '180.76.6.138', '180.76.6.45', '162.223.29.219', '180.76.5.66', '180.76.5.197', '180.76.5.63', '66.249.74.249', '66.249.74.230', '5.10.83.38', '66.249.74.25', '5.10.83.9', '66.249.77.14', '66.249.77.75', '180.76.6.56', '66.249.77.66', '5.10.83.3', '66.249.77.83', '189.15.160.188', '208.115.113.91', '180.76.6.37');

if (!in_array($userip, $nolog))
{
//carry on and log user else do nothing



See what I mean? There are millions of them that just keep coming!

I am getting sick of placing each individual IP in the $nolog array, and since most seem to share a common start of an IP, I thought I could check using strops() like I did for my HTTP_REFERER topic. However, once I created the array I get the message above. What does it even mean?

$blacklist = array('66.249.75', '66.249.73', '5.10.83');

$checkip = strpos($userip, $blacklist);
	if ($checkip === false) 
	{
//carry on else do nothing



Is This A Good Question/Topic? 0
  • +

Replies To: Warning: strpos() [function.strpos]: needle is not a string or an inte

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,767
  • Joined: 12-June 08

Re: Warning: strpos() [function.strpos]: needle is not a string or an inte

Posted 12 March 2014 - 09:13 AM

Look at the documentation: http://us1.php.net/strpos


Quote

mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
-----------
haystack

The string to search in.
needle

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

Was This Post Helpful? 0
  • +
  • -

#3 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 35
  • View blog
  • Posts: 877
  • Joined: 06-July 13

Re: Warning: strpos() [function.strpos]: needle is not a string or an inte

Posted 12 March 2014 - 09:41 AM

OK, I think I've got it now thanks.

function strpos_array($haystack, $needles = array()) 
{
        $result = array();
        foreach($needles as $needle) 
        {
                $res = strpos($haystack, $needle);
                if ($res !== false) $result[$needle] = $res;
        }
        
        if(empty($result)) return false;
        
        return min($result);
}


$blacklist = array('66.249.75', '66.249.73', '5.10.83', '5.10.83');


$checkip = strpos_array($userip, $blacklist);


Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 763
  • View blog
  • Posts: 3,327
  • Joined: 03-December 12

Re: Warning: strpos() [function.strpos]: needle is not a string or an inte

Posted 12 March 2014 - 10:11 AM

I don't know what resources it would use, but what about a txt file that stores the 'bad' IP addresses? Add a hidden link to a page disallowed in your robot.txt file. Then any IP that goes to that link is added to the file. The blacklist array pulls from that file and blocks future connection?

Just an idea.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,767
  • Joined: 12-June 08

Re: Warning: strpos() [function.strpos]: needle is not a string or an inte

Posted 12 March 2014 - 10:20 AM

.. and make sure to try and utilize a robot.txt file too.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1