php - Fatal error on session_start() -
i have function track user session time.
function sessiontracker(){ ini_set('session.cookie_lifetime', 86400); ini_set('session.gc_maxlifetime', 86400); $sid = session_id(); if ($sid != '') { //echo "session exists!"; } else { //echo "no current session exists! starting..."; session_start(); } if(!isset($_session['username'])) { header("location:login.php"); exit(); }
but i'm getting "maximum execution time of 30 seconds exceeded" when hits session_start(); line. there better function or how fix this? don't time, line.
function sessionreup() { $time = $_server['request_time']; //for 30 minute timeout, specified in seconds $timeout_duration = 1800; /* here user’s last_activity timestamp. if it’s set , indicates our $timeout_duration has passed, blow away previous $_session data , start new one. */ if (isset($_session['last_activity']) && ($time - $_session['last_activity']) > $timeout_duration) { session_unset(); session_destroy(); session_start(); header("location:login.php"); exit(); } /* finally, update last_activity our timeout based on , not user’s login time. */ $_session['last_activity'] = $time; }
the code not show line, responsible long runtime. sessions stored hard disk. device really slow? did exchanged session handler?
but can reduce code to:
session_start(); if(!isset($_session['username'])) { header("location:login.php"); exit(); }
Comments
Post a Comment