Re: Problem with app, condition not working.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris skrev:
PHP Mailer wrote:
Chris skrev:

PHP Mailer wrote:

Chris skrev:

PHP Mailer wrote:

Hey guys got a problem with an app i'm working on.
App: An app to track visitors and hosts visiting certain pages in a website. Situation: the app is to populate a table (db) with IP numbers which are to be concidered as filtered/excluded in the below snippet of code from being tracked. Problem: the below code is used to insert the actual data for the tracker from the visitor on the page its requested. However, before the actual information is submitted, there has to be a condition to see if the current visitor's IP is listed in the excluded list. My current code returns false to all, and will not input the data whether the IP is in the list or not in the table.

Culprit: Seems to be the in_array causing it or an eye-flaw from my side but cannot find it.

//======================================================
#--> Include db config
require_once("../includes/db.class.phtml");
#--> Connect to db
$sql = new conSQL();
//======================================================
#--> Fetch current rules
$currentRulesQuery = $sql->query("SELECT host FROM filter");
if(!$currentRulesQuery){ print mysql_error(); }

#--> Result to array
#.
$currentHost = $_SERVER['REMOTE_ADDR'];

/* Obs: this loop runs all the rules *** do not edit */
while($currentRules = $sql->fetchArray($currentRulesQuery, MYSQL_ASSOC))
{



If you print our $currentRules:

var_dump($currentRules);

is it an array? What's in it?


Hello Chris,

Returned output from the array is:
Array ( [0] => 127.0.0.1 [host] => 127.0.0.1 )


If you think it's the in_array - check it:

if (in_array($currentHost, $currentRules)) {
  echo "Host: $currentHost is in rules<br/>";
  var_dump($currentRules);
}

Strangest thing is:
if i add the excluded IP to the field in the DB it will insert the visitor info to the db, however if i remove the excluded ip from the filter, it wont

Then this isn't a copy / paste of your script:

   #--> If in array
   if(!in_array($currentHost, $currentRules))

Comment says one, the code says another.

Hello Chris,

Sorry about that, happens when writing it too fast and changing it too often.
Fixed the problem now, did a match in the query instead.

Thank you for the excellent help!

Jimmie

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux