Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Only for logged in customers
 
rreece0113
Sr. Member
 
Total Posts:  76
Joined:  2009-01-28
Oregon
 

This little bit of code works to check if magento has oppend an internal session for this particular visitor. If not then they are redirected to magento default customer loggin page. If they are already logged in then they are redirected and able to access other pages.

To implement this bad boy you can either add it to the top of all your .phtml template files under app/frontend/design/YOUR PACKAGE/YOUR THEME/template/page/.phtml files. Or you can add it to the header.phtml under html in the same directory.

Note that you must add this bit of code to the top of any .phtml BEFORE ANY OTHER CODE IS STARTED!

<?php if(Mage::getSingleton('customer/session')->isLoggedIn()): ?>
<?php
    $uri 
$_SERVER['REQUEST_URI'];
    if( 
$uri == "/wholesale-cart/")
    
{
    header
("Status: 301");
    
header('Location: http://www.yoursite.com/wholesale-cart/only-logged-customers/') ;
    exit; 
    
}
?>
<?php 
else: ?>
<?php 
    $uri 
$_SERVER['REQUEST_URI'];
    if( 
$uri == "/wholesale-cart/"){}
    
    
else if ($uri == "/wholesale-cart/products/")
    
{
    header
("Status: 301");
    
header('Location: http://www.yoursite.com/wholesale-cart/customer/account/login/') ;
    exit; 
    
}
?>
<?php 
endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top