Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Integration in a site : sessions

LLBLLB
edited November 2008 in Vanilla 1.0 Help
Hi,

I'm creating a web-site. I'd like to access to Vanilla functions and sessions from my web-site. When a user signs in on Vanilla forum, I'd like to get his userid and other informations in my web-site.

In a PHP file, I wrote the following lines:
error_reporting(E_ALL);
include('./forum/appg/settings.php');
include('./forum/appg/init_vanilla.php');
echo "UserID = " . $Context->Session->User->UserID;
If I put the PHP file in Vanilla directory, it works fine and I can see my UserId.
If I put the PHP elsewhere, it doesn't work: UserId is always 0.

I've searched on the forum and on search engines, but I didn't find anything. I changed the cookie path and set to "/", but this still doesn't work.

Does anyone have an idea (or a link) for my problem?

Thanks.

Comments

  • edited April 2008
    /offtopic: you can also get the userID directly from the Session object, i.e. $Context->Session->UserID you should also include the "init_people.php", i.e. include('./forum/appg/init_people.php'); maybe also the "headers.php" I assume that the paths are correct where you want the file to access from.
  • Thank you for your reply and for the tip. Unfortunately, this doesn't work. When I add your line, I get the error message:

    Fatal error: Cannot redeclare addconfigurationsetting() (previously declared in path\forum\library\Framework\Framework.Functions.php:22)

    I removed the include of "init_vanilla.php". The error message disappeared, but it still prints "0".
  • $full_path_to_vanilla = '/full/path/to/vanilla/here'; ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $full_path_to_vanilla); error_reporting(E_ALL); include('appg/settings.php'); include('appg/init_vanilla.php'); echo "UserID = " . $Context->Session->User->UserID;
  • Hi,

    This gives exactly the same result.

    My file in my "php" directory prints : "UserID = 0".
    My file in my "forum" directory includes the other page (so, I'm sure it's the same code that's executed) prints : "UserID = 1".

    I believe this is connected to sessions and paths, but I don't know exactly how things work.
  • I am having the same issue, getting the UserID from wordpress pages and also a stand alone PHP custom home page. Does it matter what path is set for your cookie? The above squirrel code works fine when the php files is inside the /forum/ (vanilla) directory. But does not work in any other directory.
  • my same problem too, if the script is ran outside of the vanilla folder, $_SESSION is completely empty...including the scripts fills the $Context object, but never gives anything other than 0 for user id... Is there ANY solution to this problem? I've scoured the forum, dived into the code and nothing explains it better than some sort of $_SESSION security to where it's not filling because the URL is different... If anybody has a solution...I've been waiting for days
  • You need to change the cookie settings; if you you forum is at www.example.com/forum, your cookie settings are probably:
    $Configuration['COOKIE_DOMAIN'] = 'www.example.com'; $Configuration['COOKIE_PATH'] = '/forum';

    If you need the session to be accessible at www.example.com/, you need:
    $Configuration['COOKIE_DOMAIN'] = 'www.example.com'; $Configuration['COOKIE_PATH'] = '/';

    If you need the session to be accessible at blog.example.com/, you need:
    $Configuration['COOKIE_DOMAIN'] = '.example.com'; $Configuration['COOKIE_PATH'] = '/';
  • If you need the session to be accessible at blog.example.com/, you need: $Configuration['COOKIE_DOMAIN'] = '.example.com'; $Configuration['COOKIE_PATH'] = '/'; I changed the cookie settings and still, same thing...$_SESSION is empty and UserID is 0 and I'm still logged into at www.example.com/forum/
  • edited October 2008
    I used this guide to integrate Vanilla and Dokuwiki:
    http://lussumo.com/docs/doku.php?id=vanilla:integration:dokuwiki

    It works.
    I've set my cookie path to '/' in Vanilla. :)
  • @PastorBones - my issue was actually with Wordpress, as I was trying to integrate the session state into the WP header. Wordpress has a function that sanitizes (and deletes) most global values, including the $_SESSION array. Not sure if there is something similar in your application or not. I doubt you are having the same issue, but thought I would mention it.
  • I just tried. I created a file you did. and tested and got a userid of 0. Then change the cookie settings and tried again without getting my userid. Finally I cleared my cookie, then logged-out,logged-in and it was finally working.
  • After changing your cookie paths and domains, don't forget to delete the existing cookies from your browser before doing anything else. If you don't, you will probably get some weird results, such as the new cookie path not being able to overwrite the old cookie path. -- JJ
This discussion has been closed.