Sunday, August 9, 2009

Oscmax/Oscommerce - Check if customer is logged in

Sometimes you might want to specify some processing to occur or something to only show up if the customer is logged in. So before you write anything you need to specify this login condition, or check if a login session has started.

This is much simpler to do than it seems. All you need is this line:

if ((tep_session_is_registered('customer_id')) && (!tep_session_is_registered('noaccount'))) {
your code
}

which basically tells the browser to check if the session is registered but make sure that it's an account (rather than PWA session).

In oscommerce, you don't need the "noaccount" session since there is no PWA allowed. So it would be:

if (tep_session_is_registered('customer_id')) {
your code
}

Replace "your code" with whatever code you have, and at the end don't forget to put the closing bracket or you'll get a parse error.

For example, the following code redirects a logged in customer to the new products page, and otherwise sends a user to the login page:

if ((tep_session_is_registered('customer_id')) && (!tep_session_is_registered('noaccount'))) {
tep_redirect(tep_href_link(FILENAME_PRODUCTS_NEW));
}
else {
tep_redirect(tep_href_link(FILENAME_LOGIN));
}

And in oscommerce:

if (tep_session_is_registered('customer_id')) {
tep_redirect(tep_href_link(FILENAME_NEW_PRODUCTS));
}
else {
tep_redirect(tep_href_link(FILENAME_LOGIN));
}

Enjoy!

4 comments:

  1. i need to have the user create account by just entering the email and password and then after creating that particular user's session redirect the user to whole checkout page which further contains the address and other necessary fields to be entered could you please help me with that

    thanks

    ReplyDelete
  2. Herzlichen Dank :-)

    ReplyDelete
  3. Thanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again. Webdesign Stade

    ReplyDelete