session - header('location:index.php') doesn't work in the first run -
i have index.php page session set inside($_session['expire']). session should unset after 30 mins , should redirect index.php (to verify user again).
some part of index.php code:
<?php session_start(); //if user name , password valid following: $_session['start'] = time(); $_session['expire'] = $_session['start'] + (30 * 60) ; ?> <a href="index.php?action=contentmanager"> content </a> <?php if(isset($_request['action'])) { //if expiration time has not reached yet next $now=time(); if (isset($_session['expire']) && ($now<= $_session['expire'])) { switch($_request['action']) { case 'contentmanager' : include('model/content.php'); $contents = getcontent($conn, ' 1=1'); include('view/contentmanager.php'); break; } } else if($now > $_session['expire']) { unset($_session['expire']); session_destroy(); header('location:index.php'); exit(); } } ?>
the problem when click contentmanager link after 30 mins, redirect empty page url: index.php?action=contentmanager
and if refresh page again, redirect index.php , login form appeared.
so breifly: have refresh page 2 times redirect right page.
thanks in advance
use ob_start();
<?php session_start(); ob_start(); //if user name , password valid following: $_session['start'] = time(); $_session['expire'] = $_session['start'] + (30 * 60) ; ?> <a href="index.php?action=contentmanager"> content </a> <?php if(isset($_request['action'])) { //if expiration time has not reached yet next $now=time(); if (isset($_session['expire']) && ($now<= $_session['expire'])) { switch($_request['action']) { case 'contentmanager' : include('model/content.php'); $contents = getcontent($conn, ' 1=1'); include('view/contentmanager.php'); break; } } else if($now > $_session['expire']) { unset($_session['expire']); session_destroy(); header('location:index.php'); exit(); } } ob_end_flush(); ?>
php session header location href
No comments:
Post a Comment