0

Whenever i open the page i receive following errors:

[04-Jul-2012 17:10:45] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/admin/header.php:39) in /home/test/public_html/admin/edAgent.php on line 80

[04-Jul-2012 17:10:55] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/admin/header.php:39) in /home/test/public_html/admin/edAgent.php on line 80

Pieces of code including headers:

Encoding header:

header('Content-Type: text/html; charset=utf-8');

Login redirect header:

if(!isset($_SESSION["login"])OR $_SESSION["login"]!=1){        
    header('Location: login.php');
    exit;     
    }

Checks if logged user has privileges to edit:

if($level!='4') {
    header('Location: acd.php?msg=1');
    exit;
}

Checks if ID exists:

if ($nUsers==0) {    
    header('Location: acd.php?msg=2');
    exit;    
}

Checks if information is editable:

if($access != '4') {        
    header('Location: acd.php?msg=1');
    exit;        
}
Pramod Kumar Sharma
  • 7,851
  • 5
  • 28
  • 53
John
  • 1,619
  • 8
  • 24
  • 34

3 Answers3

2

If you output ANYTHING to screen then, headers will write. So if you intend to use header() in your code, you must either do this before outputing anything, or right at the begining turn on output buffering using ob_start().

Joe Bowman
  • 536
  • 2
  • 8
1

If headers are already sent the JS method should work.

print '<script type="text/javascript">window.top.location.href = "'. $myurl .'";</script>';
RassK
  • 515
  • 6
  • 20
0

add ob_start(); at the start of page and ob_end_flush(); and the end of the page. Try store header() in functions though you should not have any output code after the header().

Hope it helps

JohannesAndersson
  • 4,550
  • 2
  • 17
  • 30