获取Magento用户登陆状态
用户登陆状态判断,Magento早封装好了:
1 | if ( $this ->helper( 'customer' )->isLoggedIn()) { |
2 | // is logon |
3 | } |
判断用户登陆状态是否登陆的原理是:Magento在Session中检查CustomerID是否已经设置,并且该CustomerID在数据库中是有效的。
1 | /** |
2 | * Check customer is logged in |
3 | * @class Mage_Customer_Helper_Data |
4 | * @return bool |
5 | */ |
6 | public function isLoggedIn() |
7 | { |
8 | return Mage::getSingleton( 'customer/session' )->isLoggedIn(); |
9 | } |
1 | /** |
2 | * Checking custommer loggin status |
3 | * @class Mage_Customer_Model_Session |
4 | * @return bool |
5 | */ |
6 | public function isLoggedIn() |
7 | { |
8 | return (bool) $this ->getId() && (bool) $this ->checkCustomerId( $this ->getId()); |
9 | } |
相关话题: