Support Forums

Full Version: Warning: Cannot modify header information - headers already sent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
header() has to be called before any other output.
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?
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.
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
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.
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
Line 45 must have some sort of output, what is line 45??
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!