Forum > Networking and Web Programming

Help needed for usage of session in fpweb

<< < (2/2)

william:
I have spent some time investigating the issue. The session was found to be expired immediately after creation and the issue is located to be error at iniwebsession file.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TIniSessionFactory.SessionExpired(Ini: TMemIniFile): boolean; var  L: TDateTime;  T: integer;begin  L := Ini.ReadDateTime(SSession, KeyLast, 0);  T := Ini.ReadInteger(SSession, KeyTimeOut, DefaultTimeOutMinutes);  {$ifdef cgidebug}  If (L=0) then    SendDebug('No datetime in inifile (or not valid datetime : '+Ini.ReadString(SSession,KeyLast,''))  else    SendDebug('Last    :'+FormatDateTime('yyyy/mm/dd hh:nn:ss.zzz',L));  SendDebug('Timeout :'+IntToStr(t));  {$endif}  Result := ((Now - L) > (T / (24 * 60)));  {$ifdef cgidebug}  if Result then    begin    SendDebug('Timeout :'+FloatToStr(T/(24*60)));    SendDebug('Timeout :'+FormatDateTime('hh:nn:ss.zzz',(T/(24*60))));    SendDebug('Diff    :'+FormatDateTime('hh:nn:ss.zzz',Now-L));    SendDebug('Ini file session expired: '+ExtractFileName(Ini.FileName));    end;  {$endif}end; 
Variable L was found to be zero always since Ini failed to parse the datetime it just wrote (the debugger showed that the correct text was read from the ini file)...

Here is an sample content of the ini file:

--- Code: ---[Session]
Start=26-May-2022 10:32:04
Timeout=15
Last=26-May-2022 10:32:57

--- End code ---

And my system setting of long date format is probably dd-mmmm-yyyy hh:nn:ss. I would suggest the ini session should use a fixed format instead of system setting?

Thaddy:
The cookie should store year-month-day ( TDateTime order) and UTC, since that should be programmer native and only convert for display purposes based on locale settings.
Anything other would be a common design flaw. Storing dates is not complex, but sometimes even advanced programmers fall into that trap.
So if that is the case report a bug.
BUT to my knowledge, fcl-web is correct, so likely you made a programming error where you assume your own locale and that is wrong.

See https://en.wikipedia.org/wiki/Coordinated_Universal_Time

Any software that does not adhere to UTC for date time storage would fail at different time zones.
(If I wasn't officially mad it would drive me nuts)

william:
I never change any format setting in the test program and I think there should be a bug somewhere? For example I have created a simple pascal program:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; uses SysUtils; var  dt: TDateTime;  s: string;begin  dt := Now;  s := DateTimeToStr(dt);  writeln(s);  writeln(StrToDateTimeDef(s, 0));  readln();end.
And this is the output on my PC:

--- Code: ---27-May-2022 14:28:46
 0.0000000000000000E+000
--- End code ---

william:
Verified to be ShortDateFormat issue, it seems that non-numeric month is causing the troubles. So setting the format to all numeric output fixed the session expired issue, e.g.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ShortDateFormat := 'd/m/y';

Navigation

[0] Message Index

[*] Previous page

Go to full version