alconebay Posted August 19, 2008 Share Posted August 19, 2008 I want my stat logging to ignore my work and home ip address so they don't get put into my statistics, but it's being logged anyway. What am I doing wrong? ("//begin stats logging" being my logging code which works fine) $ip=$_SERVER['REMOTE_ADDR']; if ( $ip != "11.111.11.11" || "22.222.222.222" ) //these are the IPs I want ignored { // begin stats logging... } I also tried this condition: if (( ! $ip == '111.111.11.111' ) || ( ! $ip == '22.222.22.222' )) { // begin stats logging... } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 19, 2008 Share Posted August 19, 2008 are you using static IPs? if so then hardcoding your IP address is fine, but if you have are using dynamic IP addresses then it will be really hard to hardcode your IP in the IF statement Quote Link to comment Share on other sites More sharing options...
waynew Posted August 19, 2008 Share Posted August 19, 2008 $ip=$_SERVER['REMOTE_ADDR']; if ( $ip != "11.111.11.11" && $ip != "22.222.222.222" ) //these are the IPs I want ignored { // begin stats logging... } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 19, 2008 Share Posted August 19, 2008 I would put all the IPs to be ignored in an array and then use the in_array() function: <?php $ignore_ips = array('11.22.33.44','44.33.22.11','111.222.111.222'); if (!in_array($ip,$ignore_ips)) { // // begin stats logging // } ?> This make for easy changing of the IP addresses, instead of mucking with the if statement. Ken Quote Link to comment Share on other sites More sharing options...
alconebay Posted August 19, 2008 Author Share Posted August 19, 2008 The array method works. I also tried changing the "or" ( || ) to an "and" ( && ) but it did the same thing (nothing was being logged). kenrbnsn's suggestion of an array works perfectly though. I'm still wondering why the other method of and's and or's didn't work. It seemed structurally correct... But the array is working (and it is easier) so I'll leave well enough alone. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 19, 2008 Share Posted August 19, 2008 Your other post didnt make sense, so I thought i would fix it. <?php $ip = $REMOTE_ADDR; // Bad coding practice lol if(($ip != "111.111.11.111" ) || ($ip != "22.222.22.222")){ echo '1'; }else{ echo '2'; }?> Quote Link to comment Share on other sites More sharing options...
alconebay Posted August 19, 2008 Author Share Posted August 19, 2008 What is different in your code? Also, what is the bad coding practice? I don't think I need an else statement. If the "if" condition is met the logging starts, else do nothing. Right? Thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 19, 2008 Share Posted August 19, 2008 What is different in your code? Also, what is the bad coding practice? I don't think I need an else statement. If the "if" condition is met the logging starts, else do nothing. Right? Thanks u did this if(!$quote == something) I just wanted to tell you that in your first post the second try was wrong. Thats all. use the in_array if it works. Quote Link to comment Share on other sites More sharing options...
alconebay Posted August 19, 2008 Author Share Posted August 19, 2008 Oh, the "!" placement. Gotcha. Do the quotes vs. apostrophes make a difference? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 19, 2008 Share Posted August 19, 2008 Oh, the "!" placement. Gotcha. Do the quotes vs. apostrophes make a difference? Not in this case but If you’re familiar with PHP, the difference between double and single quotes is obvious. Double quotes evaluate variables and control characters (e.g. \n or \r), whereas single quotes do not. Double quotes you can do "i can echo $var without using the period" single quote 'I can echo' . $var . 'but i need those period'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.