避免在注销时丢失信息

时间:2014-02-18 10:27:53

标签: php cookies logout session-timeout

我正在尝试为用户提供顺畅的数据输入体验,即使他们离开浏览器一段时间,然后回来发现他们已经注销,因为会话超时了。

在我的情况下,这一点特别重要,因为我要求我的用户输入可能超过100个问卷的答案(有点像所得税表格)。因此,他们无法在不经历会话超时的情况下始终无法响应所有这些答案,这是完全可以理解的。

我一直在阅读有关如何最好地保留用户输入的数据,直到超时发生并决定构建一个解决方案,其中用户的答案首先存储在会话变量中,并且在会话超时时,存储在数据库中。我还将文件名存储在发生会话超时的数据库中,这样我就可以将用户带回那个地方了。

这现在有效。因此,如果超时发生,则要求用户再次登录,然后将其带回问卷中发生超时的位置。到目前为止,非常好。

但我怀疑我的解决方案的效率。当我查看存储在客户端PC上的cookie中的会话信息(即我的PC;使用XAMMP-PHP-MySQL设置)时,我看到所有信息,我刚刚存储在数据库中,很好地坐在一个cookie中。会话超时后,cookie仍会保留在客户端的PC上。在客户端再次登录后,我是否应该将客户端cookie的内容读入新会话并不简单?我知道cookie的名称。但我找不到一个很好的例子,可以将cookie中的key =>值对读入新的会话变量。 cookie看起来像这样:

last_active|i:1392715552;loginName|s:4:"Carl";password|s:7:"secret";answer|s:17:"log in and finish";auth|s:3:"yes";logname|s:4:"Carl";LastLogin|s:19:"2014-02-18 15:59:16";SearchCredits|s:4:"1144";UniqueClockRecordID|s:13:"530320ebd7d20";ClockType|s:0:"";ClockMaterial|s:0:"";MovementDuration|s:0:"";TypeOfTrains|s:0:"";SameBarrel|s:0:"";PassingStrike|s:0:"";TypeStriking|s:0:"";StrikingMechanism|s:0:"";ChimeMelodies|s:4:"NULL";ChimeMechanism|s:0:"";BellOrGong|s:0:"";HowManyBells|s:0:"";SortGong|s:0:"";WheelsGoingTrain|s:4:"NULL";WheelsStrikingTrain|s:4:"NULL";WheelsChimingTrain|s:4:"NULL";WheelsAlarmTrain|s:4:"NULL";SubTypeLongcase|s:0:"";SubTypeChronometer|s:0:"";SubTypeStreet|s:0:"";SubTypeTable|s:0:"";SubTypeTurret|s:0:"";TypeAutoWinder|s:0:"";SubTypeWall|s:0:"";EscapementType|s:0:"";PlatformEscapementType|s:0:"";HowManyDials|s:0:"";SettingDial|s:0:"";ClockmakerOnDial|s:4:"NULL";RetailerOnDial|s:4:"NULL";CityOnDial|s:4:"NULL";CountryOnDial|s:4:"NULL";SayingOnDial|s:4:"NULL";AnythingElseOnDial|s:4:"NULL";FakeRealClockmaker|s:0:"";Clockmaker|s:4:"NULL";BestGuessClockmaker|s:4:"NULL";ClockmakerClockNumber|s:4:"NULL";ClockmakerOnClockPlates|s:4:"NULL";AnythingElseOnPlates|s:4:"NULL";OtherMarksOnClock|s:4:"NULL";ClockCountry|s:4:"NULL";EarliestClockMadeDate|s:10:"0000-00-00";LatestClockMadeDate|s:10:"0000-00-00";BestGuessClockMadeDate|s:10:"0000-00-00";MarriageOriginal|s:0:"";MarriageDescription|s:4:"NULL";Damaged|s:0:"";DamageDescription|s:4:"NULL";CaseStyle|s:0:"";BuildingType|s:0:"";CaseMaterial|s:0:"";CaseHeight|s:4:"NULL";CaseWidth|s:4:"NULL";CaseDepth|s:4:"NULL";PlinthHeight|s:4:"NULL";PlinthWidth|s:4:"NULL";PlinthDepth|s:4:"NULL";TrunkHeight|s:4:"NULL";TrunkWidth|s:4:"NULL";TrunkDepth|s:4:"NULL";HoodHeight|s:4:"NULL";HoodWidth|s:4:"NULL";HoodDepth|s:4:"NULL";CaseOther|s:4:"NULL";DialShape|s:0:"";DialDiameter|s:4:"NULL";DialHeight|s:4:"NULL";DialWidth|s:4:"NULL";DialThickness|s:4:"NULL";DialMaterial|s:0:"";FalsePlate|s:0:"";Hands|s:0:"";HandsMaterial|s:0:"";SubDials|s:0:"";ClockLevers|s:0:"";WeightSpring|s:0:"";GoingTrainWeight|s:4:"NULL";StrikingTrainWeight|s:4:"NULL";ChimingTrainWeight|s:4:"NULL";AlarmTrainWeight|s:4:"NULL";LengthSpringGoing|s:4:"NULL";HeightSpringGoing|s:4:"NULL";ThicknessSpringGoing|s:4:"NULL";LengthSpringStriking|s:4:"NULL";HeightSpringStriking|s:4:"NULL";ThicknessSpringStriking|s:4:"NULL";LengthSpringChiming|s:4:"NULL";HeightSpringChiming|s:4:"NULL";ThicknessSpringChiming|s:4:"NULL";LengthSpringAlarm|s:4:"NULL";HeightSpringAlarm|s:4:"NULL";ThicknessSpringAlarm|s:4:"NULL";GoingFusee|s:0:"";StrikingFusee|s:0:"";ChimingFusee|s:0:"";NumberOfPillars|s:4:"NULL";PlatesShape|s:0:"";PlateDiameter|s:4:"NULL";A_PlateTopWidth|s:4:"NULL";A_PlateBottomWidth|s:4:"NULL";PlateHeight|s:4:"NULL";PlateWidth|s:4:"NULL";FrameDepth|s:4:"NULL";PlateThickness|s:4:"NULL";CalendarType|s:0:"";MaintainingPowerType|s:0:"";StrikeSilent|s:0:"";RiseFall|s:0:"";PullRepeat|s:0:"";HoldFast|s:0:"";WindingKey|s:0:"";CaseKey|s:0:"";Pendulum|s:3:"yes";PendulumLength|s:6:"234567";PendulumTemperatureCompensation|s:3:"yes";PendulumTemperatureCompensationType|s:0:"";BalanceTemperatureCompensation|s:0:"";BalanceTemperatureCompensationType|s:0:"";PictureClockURL|s:4:"NULL";PictureClockImg|s:4:"NULL";AuctionedWhen|s:10:"0000-00-00";AuctionHouse|s:0:"";AuctionLotNumber|s:4:"NULL";AuctionedInCity|s:4:"NULL";RealisedAuctionValue|s:4:"NULL";RealisedAuctionValueCurrency|s:0:"";EstimatedValueClock|s:4:"NULL";EstimatedValueClockCurrency|s:0:"";MoreInfoOnClock|s:4:"NULL";OtherPartsToClock|s:4:"NULL";TickingSoundClock|s:4:"NULL";StrikingSoundClock|s:4:"NULL";ChimingSoundClock|s:4:"NULL";AlarmSoundClock|s:4:"NULL";ClockForSale|s:0:"";PriceForSale|s:4:"NULL";PriceForSaleCurrency|s:0:"";Stolen|s:0:"";MissingDate|s:10:"0000-00-00";FinalComment|s:4:"NULL";

尽管cookie内容清楚地显示了key =>值对设计,但我相信它只是写成一个长字符串。我需要某种解析器将此cookie写回新的会话变量。是否存在执行此操作的现有程序?

之前,我决定基于阅读cookie的解决方案,我希望得到一些评论,使用cookie将我的用户带回会话时间的智慧,与临时存储会话值相比就像我到目前为止在数据库中一样。

1 个答案:

答案 0 :(得分:0)

首先:在Cookie中保存密码!这在安全方面是个坏主意。

必须有一个创建这个cookie的函数(用于创建带有数组限制器的字符串的东西)。 只需还原此函数,将数据从数据中取出,然后用cookie值替换会话数组。

有用的功能:

explode

array-merge

相关问题