Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    17
    Plugin Contributions
    0

    Default Can I determine login status from JavaScript?

    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!

  2. #2
    Join Date
    May 2008
    Posts
    17
    Plugin Contributions
    0

    Default Re: Need to determine login status from JavaScript?

    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?

  3. #3
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    4,760
    Plugin Contributions
    3

    Default Re: Can I determine login status from JavaScript?

    Quote Originally Posted by lightnb View Post
    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.

    Quote Originally Posted by lightnb View Post
    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).

    Quote Originally Posted by lightnb View Post
    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
    Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    67,288
    Plugin Contributions
    6

    Default Re: Can I determine login status from JavaScript?

    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: v1.5.3]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...

 

 

Similar Threads

  1. Checking Customer Login status from my Flash application?
    By xanabobana in forum General Questions
    Replies: 7
    Last Post: 1 Aug 2011, 03:21 AM
  2. Can Attributes determine payment method?
    By wlpdrpat in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 6 Sep 2010, 09:04 PM
  3. automatically determine TAX status (from IP)
    By poosk in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 0
    Last Post: 15 Mar 2008, 08:05 PM
  4. Can I check the status of Authorize.net Transaction from Zen Cart?
    By danielrouse in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 28 Feb 2008, 10:08 PM
  5. Determine Login?
    By BrakeStorm in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 30 Aug 2007, 09:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •