php retain session across pages with redirect -


my issue similar displaying user name , user id $_session however, try , detail problem. modifying existing code add "login expiration" , "login page redirection". both modifications are in separate include files. login page redirection works fine if exclude login expiration file.

the problem $_session['url'] set in page_one.php doesn't retain session in login.php long timeout.php include active? if comment out timeout.php in requesting page (page_one.php) session works designed.

btw: session_id same in pages.

login expiration (timeout.php):

<?php if(!isset($_session['user_id']) || (time() - $_session['login_time'] > 1200)){ header("location: {$home_url}logout.php"); } else{ $_session['last_login_time'] = $_session['login_time']; // reset timer on page refresh  $_session['login_time'] = time(); } ?> 

page redirection (redirect_login.php):

<?php $_session['url'] = "http://" . $_server['http_host'] . $_server['request_uri']; ?> 

(login.php):

// if access level 'admin', redirect admin section     if($user->access_level=='admin'){          if(isset($_session['url'])) {             $myurl = $_session['url']."?action=login_success";          }         else{             $myurl = $home_url . "admin/index.php?action=login_success";         }     header("location:  {$myurl}");     }      // else, redirect 'customer' section     else{         header("location: {$home_url}index.php?action=login_success");     } 

(page_one.php):

<?php // *** contains session_start() each page *** include_once "php-login-system/config/core.php";  include "php-login-system/redirect_login.php";  include_once "php-login-system/admin/login_checker.php";  $page_title="page one.1";  include_once 'php-login-system/admin/layout_head.php';  // 20 min timer on logged in user. *** problem if enabled *** include_once 'php-login-system/timeout.php';  echo "<div class='col-md-12'>";  // parameter values, , prevent undefined index notice $action = isset($_get['action']) ? $_get['action'] : "";  if($action=='already_logged_in'){     echo "<div class='alert alert-info'>";         echo "<strong>you</strong> logged in.";     echo "</div>"; }  else if($action=='logged_in_as_admin'){     echo "<div class='alert alert-info'>";         echo "<strong>you</strong> logged in admin.";     echo "</div>"; }  echo "<div class='alert alert-success'>";  $logintimestamp = $_session['last_login_time'];     echo date("h:i:s", $logintimestamp) . "<br>"; $timestamp = time();     echo date("h:i:s", $timestamp) . "<br>";     echo ("the session time reset from: ". $_session['login_time'] . " to: " . time());   echo "</div>"; ?>  <div class='alert alert-info'> login time: <?php echo $_session['login_time']; ?><br> login id: <?php echo $_session['user_id']; ?><br> login logged t/f: <?php echo $_session['logged_in']; ?><br> login access level: <?php echo $_session['access_level']; ?><br> login last name: <?php echo $_session['firstname']; ?><br> current url: <?php echo $_session['url']; ?><br> session id: <?php echo session_id(); ?> </div>        <?php echo "</div>"; include_once 'php-login-system/admin/layout_foot.php'; ?> 


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -