how to know if someone is logged via javascript?

前端 未结 4 1396
渐次进展
渐次进展 2021-01-03 08:43

in php i would do

if (isset($_COOKIE[\'user\']) && $_COOKIE[\'user\'] == $valueFromDb)
 echo \'logged\';

But in javascript how can

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 09:21

    When you want to know if user is logged on a page to do some type of special action, I usually use a hidden input with a special name that is checked on js. If the user is logged you put that on a master page or something like that and then in js check if it exist to know if the user is logged.

    Something like:

    
    
    

提交回复
热议问题