Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
4.9k views
in Q2A Core by
I need to insert specific javascript for ckeditor, and need to check in javascript if the user is logged in in q2a.

What is the best way to do this? Is there a cookie set for logged in users that I can read using javascript?

2 Answers

0 votes
by

You can look for the cookie qa_session - it should be present if the user is logged in, and absent if not.

by
thank you. I found 4 cookies on my installation: PHPSESSID, qa_id, qa_noticed, qa_session - and will check for qa_session as you advised.
0 votes
by

Use this javascript:

// if user is not logged in, no cookie is set
if(getCookie("qa_session") == null) {  ... }

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}


hope it will help you :)
 

by
If we wanna use it for every page  where can we place this javascript code? qa-index.php calls it?
by
you can put it in qa-content/qa-page.js
by
Thank you  q2apro.com
...