You’ve got one very large issue here – you’re using $_SESSION
.
WordPress, by default, doesn’t use session variables. So isset( $_SESSION['vsp_user'] )
will always return false
because WP isn’t keeping track of things.
There are some additional changes you’ll need to make and hooks you’ll need to tie in to in order to enable sessions in WP. Just to get you started, here are some resources:
- Adding Sessions in WordPress
- Using Sessions in WordPress
- Using sessions in WordPress (Yes, this is a different article)
- How To: Enable the Use of Sessions in Your WordPress Blog
Once you’ve actually got sessions turned on, you should see far less “false positives” in your stat tracking.