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.
<?php /* * Include the Garden framework used by Vanilla. */ // Define constants like the way that Vanilla does in its index.php file. define('APPLICATION', 'Vanilla'); define('APPLICATION_VERSION', '2.0.18.8'); define('DS', '/'); define('PATH_ROOT', './forum'); // Change PATH_ROOT to the path to your forum. // Display all PHP errors for development purposes. error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR); ini_set('display_errors', 'on'); ini_set('track_errors', 1); ob_start(); // Buffer the output of the code below. require_once(PATH_ROOT . '/bootstrap.php'); // Require the bootstrap for the framework used by Vanilla. $Dispatcher = Gdn::Dispatcher(); // Declare an alias for the dispatcher. // Set up the dispatcher. $EnabledApplications = Gdn::ApplicationManager()->EnabledApplicationFolders(); $Dispatcher->EnabledApplicationFolders($EnabledApplications); $Dispatcher->PassProperty('EnabledApplications', $EnabledApplications); // Mimic the DiscussionsController(). $Controller = new DiscussionsController(); Gdn::Controller($Controller); Gdn::Request()->WebRoot(''); ob_end_flush(); // Stop and send the buffer for the code above. /* * The above code is to include Garden framework used by Vanilla, so you can use its functions. * You can put your code in this file. See the example below. * You can also make a separate file with your code and include this file by a require() above all. */ $Session = Gdn::Session(); // Declare an alias for the user session. // Check if the user session is valid. if($Session->IsValid()) echo "The user is logged in!"; // The session is valid, so the user is logged in. else echo "The user is not logged in."; // The session is invalid, so the user is not logged in. ?>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.
Fatal Error in Gdn_Dispatcher.xStart(); The "Gdn_Dispatcher" object does not have a "xStart" method. The error occurred on or near: /home/content/94/10870394/html/000hosting/crimsonlake/forums/library/core/class.pluggable.php 168: // Make sure that $ActualMethodName exists before continuing: 169: if (!method_exists($this, $ActualMethodName)) { 170: // Make sure that a plugin is not handling the call 171: if (!Gdn::PluginManager()->HasNewMethod($this->ClassName, $ReferenceMethodName)) 172: trigger_error(ErrorMessage('The "' . $this->ClassName . '" object does not have a "' . $ActualMethodName . '" method.', $this->ClassName, $ActualMethodName), E_USER_ERROR); 173: } 174: 175: // Make sure the arguments get passed in the same way whether firing a custom event or a magic one. 176: $this->EventArguments = $Arguments; Backtrace: /home/content/94/10870394/html/000hosting/crimsonlake/forums/library/core/class.pluggable.phpPHP::Gdn_ErrorHandler(); [/home/content/94/10870394/html/000hosting/crimsonlake/forums/library/core/class.pluggable.php:172] PHP::trigger_error(); [/home/content/94/10870394/html/000hosting/testcrimson/content/Home.php:25] Gdn_Pluggable->__call(); [/home/content/94/10870394/html/000hosting/testcrimson/content/Home.php:25] Gdn_Dispatcher->Start(); [/home/content/94/10870394/html/000hosting/testcrimson/index.php:15] PHP::require_once(); Variables in local scope: [MethodName] 'Start' [Arguments] array ( ) [Return] false [ActualMethodName] 'xStart' [ReferenceMethodName] 'Start' [this] array ( 'Request' => '', 'EventArguments' => array ( ), 'Returns' => array ( ), 'HandlerType' => 'NORMAL', ) Need Help? If you are a user of this website, you can report this message to a website administrator. If you are an administrator of this website, you can get help at the Vanilla Community Forums. Additional information for support personnel: Application: Vanilla Application Version: 2.0.18.8 PHP Version: 5.3.24 Operating System: Linux Server Software: Apache User Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Request Uri: /index.php?page=Home Controller: Gdn_Dispatcher Method: xStartThe 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.comfor 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