If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Code Collaboration / Can I determine login status from JavaScript?

Can I determine login status from JavaScript?

Started by lightnb on 22 Feb 2013, 5:00 PM · Views: 3,916

Results 1 to 4 of 4
22 Feb 2013, 5:00 PM
#1
lightnb avatar

lightnb

New Zenner

Join Date:
May 2008
Posts:
17
Plugin Contributions:
0

Post #1 by lightnb

I need a way for JavaScript (without an AJAX call) to know if the user is logged in or not. I suspect the best way to do this is to check a cookie. The ZenID is always set, regardless or whether a user is logged in or not. So far as I can tell, there is no additional cookie set on login. Can anyone confirm if there is an existing way to check login status?

If not, what is the most expedient way to have a IsLoggedIn cookie get set and unset at login/log out? ie. the best file and function to place the setcookie() calls?

Thanks!

22 Feb 2013, 5:12 PM
#2
lightnb avatar

lightnb

New Zenner

Join Date:
May 2008
Posts:
17
Plugin Contributions:
0

Post #2 by lightnb

In the session, what do I check for to see if logged in? When logged in I get the customers name ID, etc. Is it reliable to see if $_SESSION['customer_id'] is set as a means of determining log in status? It seems like the session should have an IsLoggedIn boolean or something?

24 Feb 2013, 12:56 PM
#3
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #3 by rodg

lightnb:

I need a way for JavaScript (without an AJAX call) to know if the user is logged in or not. I suspect the best way to do this is to check a cookie.

Seems reasonable.

lightnb:

The ZenID is always set, regardless or whether a user is logged in or not. So far as I can tell, there is no additional cookie set on login. Can anyone confirm if there is an existing way to check login status?

I could be mistaken, but the ZenID and cookies are mutually exclusive.... or putting it another way, they are two different methods of storing the same data (or a reference to the same data).

lightnb:

If not, what is the most expedient way to have a IsLoggedIn cookie get set and unset at login/log out? ie. the best file and function to place the setcookie() calls?

I'm not going to even attempt to answer this on account of the fact that there is no 'best' for all situations.

What I can/will tell you though, is that to do whatever it is you are trying to do, is probably going to have some security implications to consider, and that you should never allow access to restricted parts of a website based on client side settings (JavaScript), because unless such restrictions are also backed up by serverside restrictions it would be trivial for a hacker to abuse such scripts to gain access to your server from a 3rd party computer.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

24 Feb 2013, 3:43 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Post #4 by ajeh

When there is a $_SESSION['customer_id'] greater than 0, the customer is logged in ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!