PHP AUTH login
Hey guys,
Im brand new to the Vanilla universe. Im having a version of Vanilla2 installed on a .htaccess protected website. What i would like to do is to use the $_SERVER['PHP_AUTH_USER'] to automatically authenticate the users with, when they enter the forum.
How would you suggest to do this?
Im brand new to the Vanilla universe. Im having a version of Vanilla2 installed on a .htaccess protected website. What i would like to do is to use the $_SERVER['PHP_AUTH_USER'] to automatically authenticate the users with, when they enter the forum.
How would you suggest to do this?
0
Answers
1. Create a
Gdn_Dispatcher_BeforeDispatch_Handler($Sender)function.2. Check make sure a user isn't already signed in: 2. Check
$_SERVER['PHP_AUTH_USER']3. Look up that user in the user table: 4. If the user doesn't exist then insert the user: 5. Start the session as the user:
I did that, but the Gdn::Session()->Start($UserID, TRUE); returns null and don't do nothing
Thanks for helping
<?php // Define the plugin: $PluginInfo['HTTPAuth'] = array( 'Description' => 'HTTP / HTACCESS auto login', 'Version' => '1.0', 'Author' => "Maxime", 'AuthorEmail' => '***@gmail.com', 'AuthorUrl' => '' ); class AuthentificationHttpPlugin extends Gdn_Plugin { public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender) { //We check that the user isn't already logged if (Gdn::Session()->UserID > 0) return; //We check the htaccess login $httpusername = (string) $_SERVER['PHP_AUTH_USER']; echo('http username = ' . $httpusername); //We check if the user exists if(!Gdn::UserModel()->GetByUsername($httpusername)) { echo "<p> User doesnt exists </p>"; //If not, we create it $UserID = Gdn::UserModel()->InsertForBasic( $username, FALSE, array('ValidateEmail' => FALSE, 'NoConfirmEmail' => TRUE)); } else { echo "<p> User exists </p>"; $UserID = $httpusername; } var_dump(Gdn::Session()->Start($UserID, TRUE)); //Returns NULL } } ?>Sorry for code format, I try but I don't find how to format it fine...
Nobody have an idea of why the Gdn::Session()->Start() doesn't works ? I did search in existing plugins about a redirection to do after the Session->Start(), but I didn't find anything working
Gdn::Session()->Start() doesn't return anything, but sets the cookie. Try dumping Gdn::Session()->User after that.
Thanks so much for reply !
Gdn::Session()->Start($UserID, true);
var_dump(Gdn::Session()->User);
returns a bool(false)