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.
How would I detect someone was logged in on a non-Vanill page?
I'm integrating Vanilla into a website and would like to show if someone is/isn't logged in on a non-Vanilla page. So on my home page I would show something like "Sign Up" if someone wasn't logged in, but if they were I'd show a link to their account or something of the sort.
Basically wondering what needs to be included on those non-Vanilla pages to do that.
0
Comments
That being the case, what session/cookie variables should I be looking for?
First of all, all of the session and cookie variable names are defined in the appg/settings.php and can be customized in your conf/settings.php file. You can either include both of those files in your pages (they just contain an array of configuration settings) or you'll have to dig into them and get what the current values are and paste them into your custom code. I recommend the former simply because it will keep all of the settings in one place. The settings you are looking for in particular are:
// Session and cookie keys $Configuration['COOKIE_USER_KEY'] = 'lussumocookieone'; $Configuration['COOKIE_VERIFICATION_KEY'] = 'lussumocookietwo'; $Configuration['SESSION_USER_IDENTIFIER'] = 'LussumoUserID'; // Cookie configuration settings $Configuration['COOKIE_PATH'] = ''; $Configuration['COOKIE_DOMAIN'] = '';
You can then use those settings to retrieve values from cookies or sessions. For example, If you wanted to see if there was a vanilla-defined userid in the php session, you could do it with code like this (I haven't tested it - I'm writing as i go...):
// Make sure there is an active php session if (!session_id()) session_start(); // Look in the session for a Vanilla User ID $UserID = @$_SESSION[$Configuration['SESSION_USER_IDENTIFIER']]; // I'd then perform some sort of check on it to see that it is an integer and it is greater than zero. // If so, you've got an active session
Validating a user by cookies is a little trickier, but still very do-able. Basically, if you want your custom code to authenticate user's based on "remember me" cookies, you can do it with a db check like so:
// Retrieve the cookie values $CookieUserID = @$_COOKIE[$Configuration['COOKIE_USER_KEY']; $VerificationKey = @$_COOKIE[$Configuration['COOKIE_VERIFICATION_KEY']; // Next I'd perform some sort of string checking - ensuring that the values of CookieUserID and VerificationKey are strings and they are not empty. Then I'd continue with... if ($CookieUserID != '' && $VerificationKey != '') { // Open a connection to the database here... // Compare against db values $sql = "select UserID from LUM_User where UserID = '".SomeFunctionToFormatForDatabaseQueries($CookieUserID)."' and VerificatonKey = '".SoemFunctionToFormatForDatabaseQueries($VerificationKey)."'"; //Now retrieve the user id from the result set $UserID = 0; $Result = @mysql_query($sql, $Connection); if (!$Result) { die("Something bad happened"); } else { while ($rows = mysql_fetch_array($Result)) { $UserID = $rows['UserID']; } } // If the $UserID is still 0, there was a problem with the cookies, so wipe them out if ($UserID == 0) { setcookie($Configuration['COOKIE_USER_KEY'], ' ', time()-3600, $Configuration['COOKIE_PATH'], $Configuration['COOKIE_DOMAIN']); unset($_COOKIE[$Configuration['COOKIE_USER_KEY']]); setcookie($Configuration['COOKIE_VERIFICATION_KEY'], ' ', time()-3600, $Configuration['COOKIE_PATH'], $Configuration['COOKIE_DOMAIN']); unset($_COOKIE[$Configuration['COOKIE_VERIFICATION_KEY']]); } else { // Otherwise assign the UserID to the session... @$_SESSION[$Configuration['SESSION_USER_IDENTIFIER']] = $UserID; } }
lussumocookie(one|two)
are only set if the user checks the "remember me" button. The only other cookie set is thePHPSESSID
whose name is dictated by the$Configuration['SESSION_NAME']
.Basically, as long as the
'SESSION_NAME'
and'COOKIE_(DOMAIN|PATH)'
match you can usesession_start();
and access the current logged in user's ID at$Configuration['SESSION_USER_IDENTIFIER']
.http://www.php-opensource.co.cc/classes/vanilla-authentication-class
Very easy to use PHP class to authenticate users outside vanilla.