Using Vanilla Session Outside of Vanilla - External Session
So I'm trying to use the Vanillaforum session with my entire website, so that the user can sign up on the forums, and then that same account will be used on the rest of the website. I have some basic code that should show wheter a user is logged in or not but it's not working. Anybody able to help? Vanilla version 2.0.18.1
<?php define('APPLICATION', 'Vanilla'); define('APPLICATION_VERSION', '2.0.16'); define('DS', '/'); define('PATH_ROOT', 'http://crimsonlakemc.com/forums/'); 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"; } ?>
and I get this error message:
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in \xampp\htdocs\crimsonlakemc\content\Home.php on line 11
Warning: require_once(http://crimsonlakemc.com/forums//bootstrap.php): failed to open stream: no suitable wrapper could be found in \xampp\htdocs\crimsonlakemc\content\Home.php on line 11
Fatal error: require_once(): Failed opening required 'http://crimsonlakemc.com/forums//bootstrap.php' (include_path='.;D:\xampp\php\PEAR') in \xampp\htdocs\crimsonlakemc\content\Home.php on line 11
Comments
EDIT: vanilla Version is 2.0.18.8
So I actually just figured out that I had to change it to not use http://
But now it tells me that I am not logged in.
Anybody able to lead me with more help into using Vanilla's session outside of the forums?
Is the forums hosted on the same server as the rest of the website? It's better to use local absolute or relative file paths if this is the case.
Here's an example script I just put together that will let you check the user's session outside of Vanilla. Read the comments next to some of code to learn more about what its doing.
By the way, you can put your code and things that don't get formatted correctly in your posts here by wrapping text in three tildes above and below to make things more readable like this:
~~~
Add Pages to Vanilla with the Basic Pages app
Thanks for the tip. And also after adding that script I get this message and I have no idea why...or where it came from
Bonk
Something funky happened. Please bear with us while we iron out the kinks
What is the actual error?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Just figured out that that's not a real error.
The error was caused by the line
$Dispatcher->Start();
which is a new method in 2.1+ that's not in 2.0.18.8 that I forgot to remove. I edited the code my last post, so try the edited code.Add Pages to Vanilla with the Basic Pages app
added your modified code and the same thing happens that happened with my original code, it says that I am not logged in even though I am.
It works for me for when I'm logged in and logged out with Vanilla 2.0.18.8.
Add
var_dump($Session->User);
before the end of the file. Does it output data about the user you're logged in with, such as the user ID and name, or does it error out? You don't need to paste the output here if it does have info about the user you're logged in with.Add Pages to Vanilla with the Basic Pages app
all it outputs is this:
bool(false)
What about
var_dump($EnabledApplications);
?Add Pages to Vanilla with the Basic Pages app
This:
array(3) { [0]=> string(9) "dashboard" [1]=> string(13) "conversations" [2]=> string(7) "vanilla" }
So any ideas on why it's not picking up the vanilla session?
if the session cookie is not specific to area then there is no session. check the cookie path.
grep is your friend.
Could you explain more? I was given a script and told to change one thing about it and it would work, but it doesn;t. So I don't know where to go.
Any session only exist in the scope of the session cookie.
This is not a cross domain solution.
grep is your friend.
I'm not doing it across different domains
nevertheless you should be able to see the domain an path of the cookie. if it is not in the scope of the script the session doesn't exist.
you can set them
grep is your friend.
For the domain section do I put the direct domain to my forum or the direct domain to my website?
http://website.com
or
http://website.com/forums
Use
.example.com
for your website because you want to have access to Vanilla cookies from the script that is uploaded at another part of your website. When you change the cookie, you should sign out and sign back in to get the updated cookie.Add Pages to Vanilla with the Basic Pages app