djfox Posted May 10, 2008 Share Posted May 10, 2008 I have set for my login to last a long time but it seems like my coding doesn`t matter to the system. The time the site allows for the person to be logged in before unlogging them varies greatly. Examples of the most extremes: Sometimes, no matter how active I am, it`ll kick me off after 15 minutes. Other times, after shutting down my computer and then start it back up the next day, I`m still logged in. What would cause it to be so unstable like that? Quote Link to comment https://forums.phpfreaks.com/topic/105032-login-session-unstable-stablize-it/ Share on other sites More sharing options...
Daniel0 Posted May 10, 2008 Share Posted May 10, 2008 Under what conditions are users deemed as inactive? Quote Link to comment https://forums.phpfreaks.com/topic/105032-login-session-unstable-stablize-it/#findComment-537617 Share on other sites More sharing options...
djfox Posted May 10, 2008 Author Share Posted May 10, 2008 Not loading any of the pages on the site (visiting). Quote Link to comment https://forums.phpfreaks.com/topic/105032-login-session-unstable-stablize-it/#findComment-537619 Share on other sites More sharing options...
Daniel0 Posted May 10, 2008 Share Posted May 10, 2008 Yes, but how do you determine that using your script? Also, is the problem that the user gets logged out randomly or is it that they're displayed as inactive although they are (sort of like the who's online list on this forum)? Quote Link to comment https://forums.phpfreaks.com/topic/105032-login-session-unstable-stablize-it/#findComment-537623 Share on other sites More sharing options...
djfox Posted May 10, 2008 Author Share Posted May 10, 2008 They are logged out randomly. Stupid me forgot to post the code: <?php // Defines DEFINE('SESSION_MAGIC','sadhjasklsad2342'); // Initialization @session_start(); @ob_start(); /* Redirects to another page */ function Redirect($to) { @session_write_close(); @ob_end_clean(); @header("Location: $to"); } /* Deletes existing session */ function RemoveSession() { $_SESSION = array(); if (isset($_COOKIE[session_name()])) { @setcookie(session_name(), '', time()+(60*60*24*365), '/'); } } /* Checks if user is logged in */ function isLoggedIn() { return(isset($_SESSION['magic']) && ($_SESSION['magic']==SESSION_MAGIC)); } /* read message count */ function CountMessages($id) { if ($res=mysql_query("SELECT * FROM messagedata WHERE recBoxID=$id AND isNew=1")) { $count=mysql_num_rows($res); mysql_free_result($res); return($count); } return 0; } /* Go login go! */ function Login($username,$password) { global $nmsg, $rows; $ok=false; if ($res=mysql_query("SELECT id,level,mailNum, echo_count, status, isHold, guildLim, adult, battle, showtime FROM userdata WHERE login='$username' AND password='$password'")) { if ($rows=mysql_fetch_row($res)) { $_SESSION['sess_name'] = $username; $_SESSION['pass'] = $password; $_SESSION['gal'] = $rows[0]; $_SESSION['mail'] = $rows[2]; $_SESSION['level2'] = $rows[1]; $_SESSION['echos'] = $rows[3]; $_SESSION['status'] = $rows[4]; $_SESSION['suspend'] = $rows[5]; $_SESSION['guildnum'] = $rows[6]; $_SESSION['adult'] = $rows[7]; $_SESSION['bat2'] = $rows[8]; $_SESSION['tim'] = $rows[9]; $_SESSION['magic'] = SESSION_MAGIC; $nmsg = CountMessages($rows[0]); $ok=true; } else { include('login_failed.php'); } mysql_free_result($res); } return($ok); } /* Terminates an existing session */ function Logout() { @RemoveSession(); @session_destroy(); } /* Escape array using mysql */ function Escape(&$arr) { if (Count($arr)>0) { foreach($arr as $k => $v) { if (is_array($v)) { Escape($arr[$k]); } else { if (function_exists('get_magic_quotes')) { if(!get_magic_quotes_gpc()) { $arr[$k] = stripslashes($v); } } $arr[$k] = mysql_real_escape_string($v); } } } } // ----------------------------------------------- // Main // ----------------------------------------------- Escape($_POST); Escape($_GET); Escape($_COOKIE); Escape($_REQUEST); Escape($_GLOBALS); Escape($_SERVER); ?> Note: For those who don`t already know, this was made by the first programmer who worked on my site years back. I have lost contact with the person long ago. Quote Link to comment https://forums.phpfreaks.com/topic/105032-login-session-unstable-stablize-it/#findComment-537624 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.