tultalk has asked for the wisdom of the Perl Monks concerning the following question:

Hi:

My records in the sessions DB seem strange.

id 7032f2c7f5a2c721a483dc75fc29595e a_session $D = {'_SESSION_ID' => '7032f2c7f5a2c721a483dc75fc...

The id field contains the SID while the second field is a mystery to me.

Some record contain names and/or expiration while others are like the one above with partial SID. It has ... following the data which implied more to follow but I cant see or find anymore.

Even the last record posted/updated did not contain the updated information that was put in the $session before flush().

Expiration appears in cookie fine but not in database record.

In the cpan documentation on session table it says two records minimum required. id and a_session, id being 32 characters and a_session a text field of undetermined length. Is that text where all the added/updated params are supposed to be?

Name Type Collation Attributes Null Default Extr +a Action 1 id varchar(32) latin1_swedish_ci No +Change Change Drop Drop Primary Primary Unique Unique Index Index Spatial Spatial More 2 a_session text latin1_swedish_ci No None + Change Change Drop Drop Primary Primary Unique Unique Index Index Spatial Spatial More

My experience with DB requires set field length.

MySQL says BLOB, TEXT L + 2 bytes, where L < 2^16 (64 Kilobytes)

So do you set a size or it just floats?

Replies are listed 'Best First'.
Re: MySQL Session database record
by huck (Prior) on Mar 11, 2017 at 03:28 UTC

    "Expiration appears in cookie fine but not in database record. " The expiration of a cookie and a session are not the same and can differ. A cookie expires after a certain date. A session expires a certain number of secons after the last access of that session.

    A blob is a field of undetermined length, they can hold text or binary data. they tend to be treated differently than a text field, and yes its size just floats. in displaying data to you your mysql access program may truncate the data as not to overwhelm your display. As stevieb says using native sql calls like select will probably show you more of the data in a_session

    The data in a_session looks kinda like what Dumper produces, it may hold all the data in a format that perl can just eval to get the hash back.

    if you use Dumper on what you get back from a $session = new CGI::Session(...); call it will look something like

    $VAR1 = bless( { '_CLAIMED_ID' => 'e161892f19c7adb6bcb1e89c26398c0b', '_DATA' => { '_SESSION_ATIME' => 1489198054, '_SESSION_CTIME' => 1489198054, '_SESSION_ETIME' => 604800, '_SESSION_ID' => '223de9081eab77743d4a4a +0cdc0a10f3', '_SESSION_REMOTE_ADDR' => '192.168.231.2 +11', 'attempts' => 0, 'forename' => 'forename', 'isloggedin' => 1, 'lastname' => 'lastname', 'timein' => 1489198054, 'timeout' => 0, 'user_id' => 'uid', 'username' => 'username' }, '_DRIVER_ARGS' => { 'DataColName' => 'a_session', 'Directory' => '/tmp', 'IdColName' => 'id', 'TableName' => 'sessions' }, '_DSN' => { 'driver' => 'file', 'id' => 'md5', 'serializer' => 'default' }, '_OBJECTS' => { 'driver' => bless( { 'DataColName' => + 'a_session', 'Directory' => ' +/tmp', 'IdColName' => ' +id', 'NoFlock' => 0, 'TableName' => ' +sessions', 'UMask' => 432 }, 'CGI::Session:: +Driver::file' ), 'id' => 'CGI::Session::ID::md5', 'serializer' => 'CGI::Session::Serial +ize::default' }, '_QUERY' => undef, '_STATUS' => 23 }, 'CGI::Session' );
    i SUSPECT that the $D= part in your table is showing you the '_DATA' => subsection(key) because that is the MEAT and the other subsections(keys)data would be reset each time by the $session = new CGI::Session(...); call anyway. When i called Dumper i had asked it to sort the keys and include nice indenting. The call used in CGI::Session may have told it to not sort the keys (because it doenst matter to an eval), and to make the content as small as possible. the non sorted keys and the truncation by your mysql viewer would explain why different fields show up in different records

      Hi: My ignorance exposed I did not see the options on the SQL panel in MyPHP Admin

      $D = {'_SESSION_ID' => '7032f2c7f5a2c721a483dc75fc29595e','isloggedin' => 1,'_SESSION_ETIME' => 604800,'#<expires>#' => 0,'forename' => 'Frankly','lastname' => 'HideIt','attempts' => 0,'_SESSION_REMOTE_ADDR' => '72.168.128.201','username' => 'username','_SESSION_CTIME' => 1489152441,'_SESSION_ATIME' => 1489174279,'sessiondata2' => 'b90af5330dc2c92ec389207ee3e67374','timeout' => 1489173579,'timein' => 1489174279,'user_id' => '89','logattempttimein' => 1489152454};;$D

      Thanks for the edification. Happy Camper

Re: MySQL Session database record
by stevieb (Canon) on Mar 11, 2017 at 02:18 UTC

    What does the data look like from a native SELECT statement on the DB directly? More importantly, can you please show the code you're using to extract the data from the DB?

    To further, what is "Sessions", and what generates its records? Is it being put in place by another Perl application? If so, which one?

      Hi: Select result using lates SID logged on: a_session $D = {'_SESSION_ID' => '1603e837e501ebaaef7ce4635e... Select result using last logged out user: a_session $D = {'_SESSION_ID' => '7032f2c7f5a2c721a483dc75fc...

      The data in both a_session records is partof the SID. A normal select statement. Don't understand this question.

      use strict; use diagnostics -verbose; use warnings; use CGI; #use Carp::Always; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI qw(:standard escapeHTML); use CGI qw/:standard/; use Data::Dumper; use Digest::MD5 qw(md5_hex); use DB_File; # persistent hash database use CGI::Session; use CGI::Cookie;

        the SELECT he mentioned is a native SQL command like

        SELECT a_session FROM sessions WHERE id='7032f2c7f5a2c721a483dc75fc295 +95e';
        If you did that it may show you something like this.
        $D = {'forename' => 'forename','timein' => 1489204868,'_SESSION_ID' => + 'eb62615586d9b8a0f14f0dd3d820bf70','username' => 'username','_SESSIO +N_ETIME' => 604800,'_SESSION_CTIME' => 1489204868,'_SESSION_REMOTE_AD +DR' => '192.168.231.211','lastname' => 'lastname','user_id' => 'uid', +'isloggedin' => 1,'_SESSION_ATIME' => 1489204868,'timeout' => 0,'atte +mpts' => 0};;$D
        I am useing the native file support in CGI:Session, it stores each session record in its own file named cgisess_SID where SID is the contents of the _SESSION_ID key. as i suspected the data is a Dumper like structure of the _DATA keys value.