You might have seen in Magento we have a section for seeing the online visitors at a given time.
I am describing here the method for getting the number of online visitors, for reference see the my webstore Decrypt Web Store, I am showing the online visitors in the left column.
<?php //this code can be written directly in the template file $visitor_count = Mage::getModel('log/visitor_online') ->prepare() ->getCollection()->count(); if(!empty($visitor_count) && $visitor_count > 0) { $cnt = $visitor_count; echo 'Visitors online :'.$cnt; } ?>
Here is another way for doing this
<?php //this code can be written directly in the template file $visitor_collection = Mage::getResourceModel('log/visitor_collection')->useOnlineFilter(); $visitor_count = count($visitor_collection); if(!empty($visitor_count) && $visitor_count > 0) { $cnt = $visitor_count; echo 'Visitors online :'.$cnt; } ?>
Hope this is helpful.
nice one…! It will be better to use this method rather than using the third party extension extension…! 🙂
If you want to check if customer is already logged in from another location? then you can try the following blog article:
http://www.blog.magepsycho.com/how-to-check-if-customer-is-already-logged-in-from-another-location/
Cheers!!
thanks a bout this article. And can you write an article about total of access website, amount of access in current day and current month?
Thanks a lots.
@taly – In Magento site, when you login in adminend, you can see number of times the product viewed, I have used this in my store DecryptWeb Store, you need to modify the code for filtering as per the date. Also you can use Google Analytics for tracking your site’s user access, it will be much useful.
Hi, can u please give more instruction which file at what folder need to be edited?
And which part should be manipulated to make: if there’s no visitor, the visitor count show 5 instead of 0
Thanks
@Budi – There is no need to modify any of the default file, you can make a new block file and simply write above mentioned code or can write in any of the existing block file. The visitor counts depends on the customer logs generated in Magento, hope this helps you
Ok, works, but… it dont refresh if you have cache enabled, so It shows last counter before cache.
How Can i Fix that?
It depends on the visitors logs generated by Magento in a given time.
I derived at this code from the default Magento code for Customers->Online Customers section found in the default Magento admin end.