Jump to content

[SOLVED] Are my conditions wrong? I thought this would be simple...


alconebay

Recommended Posts

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...
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.