afro-Nija afro-Nija - 1 year ago 80
PHP Question

check if a customer is online magento

first please pardon me if my question seems a bit off but I will appreciate if someone can point me to the right direction or a sample or code that can get all currently logged in customers online programmatically.

I already found out that you can use

Mage::getSingleton( 'customer/session' )->isLoggedIn()

to find out if the current user is logged in or not but what I am asking is to check a particular user else where from his id to know if he/she is logged in or not.

and I have already posted a similar question on the magento forum incase you find out but no response yet at least till the time of this post. via this link

any help is appreciated. thanks in advance.

Answer Source

if I understand you correctly, you want to know every customers currently logged in, this code (from Mage_Adminhtml_Block_Customer_Online_Grid) should do it:

    $collection = Mage::getModel('log/visitor_online')
    /* @var $collection Mage_Log_Model_Mysql4_Visitor_Online_Collection */
    $collection->addFieldToFilter('customer_id', array('notnull' => true))->addCustomerData();

If you want to check about a particular user, replace array('notnull' => true) by the id of this customer and check if the count() of the collection is 1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download