php_guest Posted January 18, 2009 Share Posted January 18, 2009 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? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
phparray Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
php_guest Posted January 18, 2009 Author Share Posted January 18, 2009 sorry for so dummy questions but I am a beginner: I still can't find the clue about connection of TRACK_VISITOR,true for if (TRACK_VISITORS) and if(!TRACK_VISITORS). Does if(!TRACK_VISITORS) mean if there is no record yet, then perform if statement? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 18, 2009 Share Posted January 18, 2009 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? Quote Link to comment Share on other sites More sharing options...
php_guest Posted January 18, 2009 Author Share Posted January 18, 2009 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(); } 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.