Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Warning: Cannot modify header information - headers already sent
#1
first off, i'm not sure if this is the correct subforum to submit this problem; apologies if it isn't.

The problem is:

Quote:Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\include\php_layout\admin_suite\header.php:45) in C:\xampp\htdocs\admin\admin_webmasterqueries.php on line 166

admin_suite\header.php:
PHP Code:
include("../include/session.php");
    if(!
$session->isAdmin()){header("Location: ../game/index.php"); exit;}
    else{ 
//Display everything below if user is not logged in
        
include("../include/php_layout/admin_suite/header.php"); //header 

line 166 in delete function:
PHP Code:
//code executes if admin decides to delete query
    
if($id == "delete" && $status == "delete") {
        
        
//Added for furthur security measures - [Second check that user is authorised]
        
if(!$session->isAdmin()){header("Location: ../game/index.php");}else{
        
        
$query_id $_GET['queryID']; //Gets the querie's ID
        
$q "DELETE FROM contactwebmaster_requests WHERE wmqueryID='$query_id' LIMIT 1";
        
$query_delete $database->query($q) or die("MySQL error: ".mysql_error());;
        
header("Location:".$session->referrer."");}
        
    }
//if ID=delete 

line 166 being:
Quote:header("Location:".$session->referrer."");}


I can't seem to figure out why its saying headers have already been sent? Any help would be seriously appreciated Smile
Reply
#2
header() has to be called before any other output.
MyBB Support Team Lead
Reply
#3
Thank you MattR for your reply.

I need it to execute these three lines of code:

PHP Code:
$query_id $_GET['queryID']; //Gets the querie's ID
        
$q "DELETE FROM contactwebmaster_requests WHERE wmqueryID='$query_id' LIMIT 1";
        
$query_delete $database->query($q) or die("MySQL error: ".mysql_error());; 

before the user is redirected, how can i make it so the header is called before input and make it run this code?
Reply
#4
Try using output buffering. Put ob_start() a line before the header and ob_flush() after the important line you want to execute so that the header will be sent later after execution. Hope this helps.
Reply
#5
PHP Code:
//code executes if admin decides to delete query
    
if($id == "delete" && $status == "delete" && $session->isAdmin()) {
        
        
ob_start();
        
header("Location:".$session->referrer."");  //UNRESOLVEDISSUE
        
        
        
$query_id $_GET['queryID']; //Gets the querie's ID
        
$q "DELETE FROM ".TBL_WMQUERIES." WHERE wmqueryID ='$query_id' LIMIT 1";
        
$database->query($q) or die("MySQL error: ".mysql_error());
        
ob_flush();
        
    }
//if ID=delete 

I'm using that if that was what you meant blackstrider?
Still gives me the same error, am i using it right?
The three lines of code are excuting because i made it display a MySQl errror from it. Still seems to be the header code that is giving me problems
Reply
#6
Try putting ob_start() at the very first line of your php code and the other one at the very last. I'm not so sure about it but it helped me with the same error I'm having before.
Reply
#7
still no joy. The .php code is working as the items are being deleted from the databse but i'm still getting the header error Sad
Reply
#8
Line 45 must have some sort of output, what is line 45??
MyBB Support Team Lead
Reply
#9
I sorted it by putting:

PHP Code:
    //code executes if admin decides to delete query
    
if($id == "delete" && $session->isAdmin()) {
        
ob_start(); header("Location:".$session->referrer."");
        
        
$query_id $_GET['queryID']; //Gets the querie's ID
        
$q "DELETE FROM ".TBL_WMQUERIES." WHERE wmqueryID ='$query_id' LIMIT 1";
        
$database->query($q) or die("MySQL error: ".mysql_error());
        
ob_flush();
        }
//if ID=delete 

and:

PHP Code:
<?php ob_start(); ?>
on line 1 of header.php



thanks for the help anyways guys!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change warning level color with php [help] KingOfHunt3rs 0 960 12-04-2014, 08:45 AM
Last Post: KingOfHunt3rs
  [TUT] How to make, and call headers and footers. Extasey 0 601 05-12-2010, 10:42 PM
Last Post: Extasey

Forum Jump:


Users browsing this thread: 1 Guest(s)