real_escape_string($_POST['username']); $password=$mysqli->real_escape_string($_POST['password']); $qu=$mysqli->query("select * from zwuser where zwuser='$username' and zwpass='$password'"); if ($qu->num_rows>0){ $user=$qu->fetch_object(); // login ok $claims=array('sub' => $user->zwuser,'nickname' => $user->zwnamen,'theme' => $user->zwtheme,'menu' => $user->zwmenu,'home' => $user->zwhome,'uida' => $user->zwuida,'uidb' => $user->zwuidb,'uidc' => $user->zwuidc,'lang' => $user->lang); $token=generateToken($claims); setcookie("token",$token,time()+720000); include($zwpath."/app/main/zw.inc"); }else{ // login not ok include($zwpath."/app/main/nologin.inc"); } }else{ if (isset($_COOKIE['token'])){ $claims=getVerifiedClaims($_COOKIE['token']); if ($claims === false){ //invalid token include($zwpath."/app/main/unauthorized.inc"); }else{ //valid token --- generate new with same data but new ttl $token=generateToken($claims); setcookie("token",$token,time()+720000); include($zwpath."/app/main/zw.inc"); } }else{ include($zwpath."/app/main/unauthorized.inc"); } }} ?>