hi!

if ( !isset($_SESSION['account']) || (isset($_SERVER['HTTP_USER_AGENT']) && (!stristr($_SERVER['HTTP_USER_AGENT'], 'yahoo') || !stristr($_SERVER['HTTP_USER_AGENT'], 'bing')) ) ) { 
        echo "user";
    }else {
         echo "unknown";
    }
    

it prints always "user".

Where is wrong? thanks!

    So, it will echo "user" if

    1) the $_SESSION['account'] is not set

    OR

    2) the $SERVER['HTTP_USER_AGENT'] is set AND $SERVER['HTTP_USER_AGENT'] does not contain "yahoo" OR "bing"

    So for most users the "$_SERVER['HTTP_USER_AGENT']" is set and they will not likely be "yahoo" or "bing" so this by itself will echo user.

    Also most users are not logged in by default, which I am guessing the $_SESSION['account'] is a designed to determine, meaning in most cases this will also echo "user".

    Basically there is no circumstance under which any visitor would see anything other that "user".

    Hope the break down helps. Its a hard to find bugs that maybe more related to what may or may not have happened prior to that point in your code.

      Krik;10994863 wrote:

      So, it will echo "user" if

      1) the $_SESSION['account'] is not set

      OR

      2) the $SERVER['HTTP_USER_AGENT'] is set AND $SERVER['HTTP_USER_AGENT'] does not contain "yahoo" OR "bing"

      I agree.

      My goal is to detect the user is not logged in AND it is not a bot.

      Of course, i change my UserAgent to test the code, but it returns always "user" (example label).

        Change the || to &&

        if ( !isset($_SESSION['account']) &&  (isset($_SERVER['HTTP_USER_AGENT']) && (!stristr($_SERVER['HTTP_USER_AGENT'], 'yahoo') || !stristr($_SERVER['HTTP_USER_AGENT'], 'bing')) ) ) { 
                echo "user";
            }else {
                 echo "unknown";
            }
        

          Should maybe add that if a user is behind a proxy that is not sending the user agent, they will also see the "unknown" with that code.

            Krik;10994869 wrote:

            Should maybe add that if a user is behind a proxy that is not sending the user agent, they will also see the "unknown" with that code.

            sorry i made a mistake: I want to detect the user is not logged in OR it is not a bot.

              Your approach was making things complicated so I had to change things. It was impossible to get it to work with just a simple if/else.

              if (isset($_SESSION['account']))
              {
              	echo "account holder";
              }
              elseif (!isset($_SERVER['HTTP_USER_AGENT']) || (isset($_SERVER['HTTP_USER_AGENT']) && (!stristr($_SERVER['HTTP_USER_AGENT'], 'yahoo') || !stristr($_SERVER['HTTP_USER_AGENT'], 'bing'))))
              {
              	echo "guest";
              }
              else
              {
              	echo "bot";
              }
              

              Basically I first found all the logged in users and got them out of the way. With them out of the way I then looked for anyone that is not a bot. And lastly all that would be left is bots.

                Couple of things about this line:

                elseif (!isset($_SERVER['HTTP_USER_AGENT']) || (isset($_SERVER['HTTP_USER_AGENT']) && (!stristr($_SERVER['HTTP_USER_AGENT'], 'yahoo') || !stristr($_SERVER['HTTP_USER_AGENT'], 'bing')))) 

                Firstly, [man]stripos[/man] would be a better choice than [man]stristr[/man] (since the latter creates a new string instead of just an integer).

                Secondly, the second isset() is redundant. You've already tested whether or not $_SERVER['HTTP_USER_AGENT'] is set; you don't need to test it again when you already know what the answer will be.

                elseif (!isset($_SERVER['HTTP_USER_AGENT']) || (stripos($_SERVER['HTTP_USER_AGENT'], 'yahoo') !== false) || (stripos($_SERVER['HTTP_USER_AGENT'], 'bing') !== false))
                
                  Write a Reply...