Jump to content

Need a help


php_guest

Recommended Posts

I was looking on http://evolt.org/node/60384 at the line

define("TRACK_VISITORS", true)

 

If you search for TRACK_VISITORS on this page you will find it inside if statements. For example:

if(TRACK_VISITORS){

        /* Calculate number of users at site */

        $this->calcNumActiveUsers()

 

I don't understand if(TRACK_VISITOR){. So if TRACK_VISITOR exist if statement is execute. And because TRACK_VISITORS is set as true, if(TACK_VISITORS) will be allways executed.

 

Also

if(!TRACK_VISITORS) return;

      $q = "REPLACE INTO ".TBL_ACTIVE_USERS." VALUES ('$username', '$time')";

      mysql_query($q, $this->connection)

will never be executed because TRACK_VISITORS is true.

 

Am I right?

Link to comment
Share on other sites

The define statement is used to define a constant. The idea of this sort of thing is that you can change how the script runs very easily. In this case, you can change whether or not you want to track the visitor simply by changing that one definition to true/false. With a single change, all the if statements using that constant will evaluate to either true or false.

 

Another common constant you might see is one that is used for debugging. You might define a constant which is used to check whether or not the script should output error information. The error information is useful when you're developing, but a security concern when the script is live. By setting a constant and testing its value, you can easily change the script to be suitable for whichever environment it is in.

Link to comment
Share on other sites

constants.php is a configuration file.  You would change true to false if your intent was to not track visitors.  So you are correct if set to true visitors are tracked and anything in if(TRACK_VISITORS) will execute to track the them.  If it is set to false visitors are not tracked.

Link to comment
Share on other sites

Does if(!TRACK_VISITORS) mean if there is no record yet, then perform if statement?

 

if(!TRACK_VISITORS) means that the if statement will be executed if TRACK_VISITORS is set to false. Though it is currently true, other people using the script (or the same person some other time) might not wish to track the visitors. They can do this just be changing the one line where TRACK_VISITORS is defined.

 

Make sense?

Link to comment
Share on other sites

Not sure, it makes no sense to me. If it is set as true then only function calcNumActiveUsers() will be performed, but it will be always zero because at the same time adding new members into table will be disabled as adding new users is inside !TRACK_VISITORS if statements.

 

So actually you need to set as false to be able to track new users, true is only to check number of users without refreshing and adding new users into calculation. That is how I understand so far.

 

      if(TRACK_VISITORS){

        /* Calculate number of users at site */

        $this->calcNumActiveUsers();

 

function calcNumActiveUsers(){

      /* Calculate number of users at site */

      $q = "SELECT * FROM ".TBL_ACTIVE_USERS;

      $result = mysql_query($q, $this->connection);

      $this->num_active_users = mysql_numrows($result);

 

 

  function addActiveUser($username, $time){

      $q = "UPDATE ".TBL_USERS." SET timestamp = '$time' WHERE username = '$username'";

      mysql_query($q, $this->connection);

     

      if(!TRACK_VISITORS) return;

      $q = "REPLACE INTO ".TBL_ACTIVE_USERS." VALUES ('$username', '$time')";

      mysql_query($q, $this->connection);

      $this->calcNumActiveUsers();

  }

 

  /* addActiveGuest - Adds guest to active guests table */

  function addActiveGuest($ip, $time){

      if(!TRACK_VISITORS) return;

      $q = "REPLACE INTO ".TBL_ACTIVE_GUESTS." VALUES ('$ip', '$time')";

      mysql_query($q, $this->connection);

      $this->calcNumActiveGuests();

  }

 

  /* These functions are self explanatory, no need for comments */

 

  /* removeActiveUser */

  function removeActiveUser($username){

      if(!TRACK_VISITORS) return;

      $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE username = '$username'";

      mysql_query($q, $this->connection);

      $this->calcNumActiveUsers();

  }

 

  /* removeActiveGuest */

  function removeActiveGuest($ip){

      if(!TRACK_VISITORS) return;

      $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE ip = '$ip'";

      mysql_query($q, $this->connection);

      $this->calcNumActiveGuests();

  }

 

  /* removeInactiveUsers */

  function removeInactiveUsers(){

      if(!TRACK_VISITORS) return;

      $timeout = time()-USER_TIMEOUT*60;

      $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE timestamp < $timeout";

      mysql_query($q, $this->connection);

      $this->calcNumActiveUsers();

  }

 

  /* removeInactiveGuests */

  function removeInactiveGuests(){

      if(!TRACK_VISITORS) return;

      $timeout = time()-GUEST_TIMEOUT*60;

      $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE timestamp < $timeout";

      mysql_query($q, $this->connection);

      $this->calcNumActiveGuests();

  }

 

 

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.