The script begins with call to session_start(), which tells PHP to create a blank file in your sessions directory.
If you don't have a dedicated session directory because you're hosted on a shared server, it isn't a good idea to rely on the default session's directory. Since all of the servers' users share the same sessions directory, you could end up counting files that aren't coming your visitors. To solve this problem, simply add this line at the top of your script:
session_save_path("/path/to/custom/directory");
After this, we define the timeframe (in minutes) that we allow users to be idle for:
define("MAX_IDLE_TIME", 3);
Essentially, if a visitor does not request a new page from the server within this timeframe (in this case 180 seconds), his session file will be ignored and not added to the visitor count.
Hold on. You might remember me saying, "built in garbage collector" earlier, and wondering why this line is necessary. There is, in fact, a built in garbage collector. The only problem with it is that by default, php.ini sets the random chance for the collector to be run at 1%. For smaller sites that don't get much traffic, this could lead to inaccurate results because the script would count old sessions more often than not.
Todas las fotos de pepe →
Amigos/Favoritos de pepe →
Todas las fotos
de pepe
Amigos/Favoritos
de pepe
© 2008-2024 · Cacholog.com