Staying logged-in
The log-in information is stored in a cookie which expires after 90 days. This is quite comfortable but could be a security risk, if you forget to logout in a i-net caffè ort on a pc used by many people.

Last edited by NilsLindenberg:
Modified links pointing to docs server
Mon, 28 Jan 2008 00:12 UTC [diff]


It would be better if a user could decide to be logged-out or to stay in.

I stuck some piece of code together. I know that stay_logged_in is a very uncreative name (loged-in with one or two g?), and the code needs someone to look over it. I am for example not sure if an enum in the table would be better. But to my great astonishment, it seems to work. :) --NilsLindenberg
Two gs: "logged in" (fixed in code samples below - hope I didn't miss any). -- JavaWoman

1) adding field to user table:

SQL-query:
ALTER TABLE `wikka_users` ADD `stay_logged_in` ENUM( 'Y', 'N' ) DEFAULT 'N' NOT NULL;


2) adding a table row to show the status of the variable (to actions/usersettings.php):

change
<tr> <td align="right">Show comments by default:</td> <td><input type="hidden" name="show_comments" value="N"><input type="checkbox" name="show_comments" value="Y" <?php echo $user["show_comments"]
"Y" ? "checked=\"checked\ : ?> /></td> </tr> <tr> <td align="right">RecentChanges display limit:</td> <td><input name="changescount" value="<?php echo htmlspecialchars($user["changescount"]) ?>" size="40" /></td> </tr>




3) added the user-table-update in actions/usersettings.php:

change:



to



4) replace the function SetUser() in wikka.php with the following one:

            /**
    * Sets cookie with name and passwort for a given user.
    *
    * Based on a given username, the name and the passwort of the user are stored
    * in a cookie on his computer. A user can choose with the config-option
    * "stay_logged_in", if the cookie is valid for a session, or for 90 days.
    *
    * @package  wikka
    * @subpackage   user
    * @name     SetUser
    *
    * @author       probably Hendrik Mans
    * @author       {@link http://wikka.jsnx.com/NilsLindenberg Nils Lindenberg} (choice between cookies)
    * @version      2.0
    * @since        probably wakka 1.0
    *
    * @input        string $user mandatory; name of the user
    *
    */

    function SetUser($user)
    {
        $_SESSION['user'] = $user;
        if ($user['stay_logged_in'] == 'Y')
        {
            $this->SetPersistentCookie('wikka_user_name', $user['name']);
            $this->SetPersistentCookie('wikka_pass', $user['password']);
        }
        else
        {
            $this->SetSessionCookie('wikka_user_name', $user['name']);
            $this->SetSessionCookie('wikka_pass', $user['password']);
        }          
    }


older discussion off-topic ;-)

Thank you. But seems like you get to like the different issue-different page think ;-) --
NilsLindenberg

ummm, not really. Two things. When there is what I think of as a code solution or proposed code solution that is useful then I think it's useful to then distinguish it in a section of its own because then it's easier for others to find. Your solution was a good one, and so should be recognized as such & be more easily available to the whole community. Secondly, from a server-owner perspective, it can boil down to server-hits & storage space. A continuing discussion on one page where 90% of the content deals with other issues means that every time somebody adds a new note ALL the page is saved....all the content travels out, all the content in, and the whole record each time is stored as latest='N' and disproportionately (relative to the conversation) increases the size of the database (which then affects processing time & amount of server memory utilized & thoughput on the harddrives etc). So, to me, it makes sense to put active discussions like I've described on a separate page so that bandwidth & storage accrues more-or-less just to the topic in discussion and not ALL of the content. (I don't know anything about the wikka server....Jason could be running wikka on a 500celeron box, or on a big one......so for the latter my concerns would not matter, for the former they would....but I tend to err on the side of conservatism (probably the only issue in my life that I do)) Cheers, Mike

"When there is what I think of as a code solution or proposed code solution that is useful then I think it's useful to then distinguish it in a section of its own because then it's easier for others to find." I admit i had to read the sentence three times :-) Nils Sorry, I'll try to write more clearly. [I started writing, "less convolutedly" and then realized that didn't help matters]. ; ) --
GmBowen


CategoryUserContributions
Comments
Comment by ChristianBarthelemy
2004-12-17 13:28:05
It does not work properly on my installation as the persistent cookie is not kept I always have to sign in...
I just wonder why this code in the SetUser() function:
if ($user['stay_logged_in"'])
Why do we have this double quotes?

Maybe it would be simpler to use a checkbox in the usersettings action as the value has anyway to be boolean?
Comment by JavaWoman
2004-12-17 15:16:32
Maybe I'm guilty - I was replacing double quotes by single quiotes and maybe Chritian copied while I was working on that?

Note that a checkbox does not by itself yield a boolean (although it is the most logical control to match a boolean) - you'd also have to change how the data is put into the database.
Comment by NilsLindenberg
2004-12-17 18:01:13
The code is now changed. You have a checkbox instead. Christian, you have to drop the old row in the table, cause the type has changed!
Comment by ChristianBarthelemy
2004-12-17 18:21:24
It works perfectly: I recommend this modification to be part of all Wikka installation!
Comment by DarTar
2005-10-13 09:32:20
Nils, could you please take a look at RogerD's question when you have one minute? :)
Comment by NilsLindenberg
2005-10-14 15:30:05
>The MySQL table gets updated once the checkbox is ticked.

So you see an "Y" in the field for your username?

>My question is this : am I correct to assume that the above instruction ( >"replace the function SetUser() in wikka.php with the following one ) >refers to the following code:

yes, thats true. Could you please add the line
var_dump($user['stay_logged_in']);
before the line with the if ($user[... in the SetUser and tell me the output?
Comment by WheelDog
2006-10-26 21:08:07
I'm running a new installation of Wikka Wikki for my fourth grade class. We have to share computers, and I'd like to have the session end in a few hours, or when the browser closes, so that other students don't come to the site with the browser already logged in for another user...The code on this page seems to reference a release prior to 1.1.6.2. How can I limit the session time in the newer version? Is there a setting somewhere that I'm not seeing?
Comment by DarTar
2006-10-28 06:46:39
Hi Doug, nice to hear from you again.
As of 1.1.6.2, there is no built-in option to set the expiry time of a session/cookie, although this is technically possible (http://www.php.net/manual/en/ref.session.php, http://www.php.net/setcookie). Maybe Nils - who was working on the 'stay logged in' option - wants to take a look at the code to take into account Doug's suggestion?
Comment by WheelDog
2006-10-28 23:31:17
Thanks for confirming what I suspected. I'd be happy to revise a line of code in a file somewhere if I knew for certain where to look - what to do. I don't need a user option type of solution, just a coding hack. I'm not fluent enough with PHP to understand where to make any changes.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki