yeahz Posted March 5, 2009 Report Share Posted March 5, 2009 Kā lai uzliek ka sesija beidzas? Piemēram, pēc 3 h pēc ielogošanās lietotājs automātiski izlogosies? Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted March 5, 2009 Report Share Posted March 5, 2009 Glabā sesijas mainīgajā: $_SESSION['valid'] laiku, līdz kuram sesija ir derīga. Kad lietotājs vēršas pie lapas, ja ir derīga sesija un ja laiks nav pārsniegts, nomaini $_SESSION['valid'] uz now()+3stundas, savukārt, ja šī brīža laiks ir lielāks, nekā $_SESSION['valid'], tad iznīcini sesiju un liec lietotājam logoties vēlreiz. Quote Link to comment Share on other sites More sharing options...
yeahz Posted March 5, 2009 Author Report Share Posted March 5, 2009 (edited) Īsti nesapratu. Kaut kā šādi? if (!$_SESSION['user_id']) { session_destroy(); } un kā arī login skriptā $_SESSION['user_id'] = time()+3600*3; Kaut kas datubāzē ir jāglabā arī? Edited March 5, 2009 by yeahz Quote Link to comment Share on other sites More sharing options...
marcis Posted March 5, 2009 Report Share Posted March 5, 2009 Ne gluži. if(!empty($_SESSION['valid']) && $_SESSION['valid']>=time()){ $_SESSION['valid']=time()+60*60*3; }else{ session_destroy(); } Quote Link to comment Share on other sites More sharing options...
yeahz Posted March 5, 2009 Author Report Share Posted March 5, 2009 Tagad ir tā ka es ielogojos, it kā viss ok, bet kad kaut ko sāk darīt, tad izlogojas. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted March 5, 2009 Report Share Posted March 5, 2009 Parādi pilnu kodu. Quote Link to comment Share on other sites More sharing options...
yeahz Posted March 5, 2009 Author Report Share Posted March 5, 2009 Pats sapratu problēmu - ielogojoties nebiju ielicis šo $izlogojas = 60*60*3; $_SESSION['valid']=time()+$izlogojas; Tagad viss strādā, bet tas nekas ka es noņēmu empty($_SESSION['valid']) un tagad kods izskatās šāds if ($_SESSION['valid']<=time()) { session_destroy(); } Viss it kā strādā kā pienākas, bet tas taču neko nemaina? Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted March 5, 2009 Report Share Posted March 5, 2009 Nu, itkā ir ok, taču tā nav laba prakse, pieļaut neinicializētus mainīgos. Quote Link to comment Share on other sites More sharing options...
yeahz Posted March 5, 2009 Author Report Share Posted March 5, 2009 Ko tas nozīmē? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.