0

I have a php page (index.php) in which after verifying the username and password a session will be set($_SESSION['expire']) that will be expired and unset after 30 mins (30 mins after pressing the login button) and will redirect us to index.php again:

header('location:index.php');

After verifying, a menu will be shown in index page that one of its item is ContentManager.php. As shown below by clicking this item we will connected to the db and will enter contentmanager.php

switch($_REQUEST['action'])
{
case 'ContentManager' : 
include('model/content.php');
$contents = getContent($conn);
include('view/contentmanager.php');
break;
}

in the ContentManger.php I have:

<?php
//if the session is not unset and expired yet
    if ( isset($_SESSION['expire']) && ($now<= $_SESSION['expire']))
{   
?>
do sth...

<?php
}
else
{
//unset the session and redirect to index.php again
unset($_SESSION['expire']);
session_destroy(); 
header('location:../index.php');}
?>

This works fine, but the problem is that after passing 30 mintues I have to press "ContentManager" 2 times to redirect to index.php If I just press it one time a blank page with be shown. But by refreshing the page for second time it will redirect to login page (index.php) again.

Please help me...

Az Dr
  • 90
  • 2
  • 9

3 Answers3

1

check your spacing before header include .it may cause error while redirecting.and another solution is check your output buffering is you output buffering set to off or on. To check this got to your servers php.ini file and check output buffering .If its off then set it on and if you don't have excess to edit php.ini file you may also on this typing the following code <?php ob_start();?> you must write this code for each page and to off output buffering type <?php ob_end_flush();?>

0

Its because youre outputting text (probably a blank line) before the header. In the example you posted it will output a the blank line between the ?> and the

Eric
  • 2,056
  • 13
  • 11
-1

I think this will resolve:

<?php
//if the session is not unset and expired yet
    if ( isset($_SESSION['expire']) && ($now<= $_SESSION['expire'])):
?>
do sth...

<?php
else {
//unset the session and redirect to index.php again
unset($_SESSION['expire']);
session_destroy(); 
header('location:../index.php');}

endif
?>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Alynva
  • 499
  • 7
  • 10