Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Recognizing authenticated users outside the forum

rstoberrstober New
edited June 2011 in Vanilla 2.0 - 2.8
I have a custom PHP-driven site (not wordpress or any other CMS). I have embedded the Vanilla 2 forum. You can see the site here: http://www.openlava.net/index.php?tb=forum.

I'd like to be able to recognize logged in users from pages that are outside the forum. I've tried printing the global $_SESSION and $_COOKIE arrays from my main page but I don't see any session variables or cookies that are associated with the forum...

How can get information about Vanilla 2 logged in users from outside the forum? Can anyone point me to an example?

Thank you, Robert
Tagged:

Best Answer

  • AoleeAolee Hobbyist & Coder ✭✭
    Answer ✓
    i think had the same problem before

    hope this will help.

    add this somewhere in your code

    define('APPLICATION', 'Vanilla'); define('APPLICATION_VERSION', '2.0.16'); define('DS', '/'); define('PATH_ROOT', 'path-to-forum'); ob_start(); require_once(PATH_ROOT.DS.'bootstrap.php'); ob_end_clean(); // clear any header output from vanila $Session = Gdn::Session(); $Authenticator = Gdn::Authenticator(); if ($Session->IsValid()) { $Name = $Session->User->Name; echo "You are logged in as $Name"; } else { echo "You are not logged in"; }

    it was taken here http://www.vanilla-wiki.info/Code/Authorization

    this helped me integrate openclassifieds to vanilla 2. :)

    if you're looking for the $_SESSION thing do this

    print_r($Session)

    and you'll get what you need.


Answers

  • I can rephase the question this way: how can I print out the session and/or cookie variables that are being set by Vanilla from within Vanilla? What Vanilla php file could I add debug statement to to print them out?

    // print out session vars
    var_dump($_SESSION);

    // print out cookies vars
    var_dump($_COOKIE);

    If vanilla is setting cookies or session variables I should be able to use them too. Can anyone provide a hint?
  • I was thinking about this some months ago, and finally i am getting some kind of working example, and i have realised an example wp plugin. If yo are interested you can take a look onto http://vanillaforums.org/discussion/comment/140789#Comment_140789
    If you have some questions, feel free to ask, if i can, i will help you.
  • Thanks e01. I downloaded the WpComments.zip and took a look at the PHP. I apologize but I don't get it. Are you saying that the authenticated user's name is in $Session->User->Name? How come I don't see that when I dump the contents of the $_SESSION array?

    How can I print out the Vanilla 2 session variables from out side the forum?
  • AoleeAolee Hobbyist & Coder ✭✭
    Answer ✓
    i think had the same problem before

    hope this will help.

    add this somewhere in your code

    define('APPLICATION', 'Vanilla'); define('APPLICATION_VERSION', '2.0.16'); define('DS', '/'); define('PATH_ROOT', 'path-to-forum'); ob_start(); require_once(PATH_ROOT.DS.'bootstrap.php'); ob_end_clean(); // clear any header output from vanila $Session = Gdn::Session(); $Authenticator = Gdn::Authenticator(); if ($Session->IsValid()) { $Name = $Session->User->Name; echo "You are logged in as $Name"; } else { echo "You are not logged in"; }

    it was taken here http://www.vanilla-wiki.info/Code/Authorization

    this helped me integrate openclassifieds to vanilla 2. :)

    if you're looking for the $_SESSION thing do this

    print_r($Session)

    and you'll get what you need.


  • Thank you Aolee! That's exactly what I was looking for. :-)
  • I am new to Vanilla Forums. I am not being able to correctly define path_root. Need help
  • Sorry for asking in this thread, but I wasn't allowed to create a new one. I run a django based site, and for me it would be better to store the sessions in the database, so I could create/read them from there, and login people to Vanilla via Django (django is Python, vanilla is PHP).

    The sites aren't on the same domain, but they have access to the same database. If there is another way this can be achieved, please let me know.
  • edited January 2012

    @AoleeI I get the following error when trying this Class 'Gdn' not found?

Sign In or Register to comment.