Jump to content

Recommended Posts

A header() redirect must come before any other output is sent to the browser. If you could actually send output to the browser, then redirect, it would waste your hosting bandwidth every time it did it, so, you are actually lucky that you cannot send output before a header.

 

The specific error message that you get tells you where the output is being started at that is preventing the header() from working. You must find and either eliminate the output (some times it is due to an incorrectly saved file format) or move the output so that it occurs after the header() or move the header() so that it is before any output.

The short, simple crude version is.. once that <html> tag is output and read by your browser, there is no room for more headers to be sent out. They have already been read and interpreted.

 

So if you need to have modified headers of any sort they must be setup prior to the <html> tag. However, don't output anything other then those headers prior to the <html> tag, or you will end up with other errors, be it with the PHP itself, or cross browser compatibility issues or what ever..

 

So I am assuming your attempting to do something with sessions, as thats what I see most commonly with the error your mentioning. If so, modify your site by

going a line above <html> and put <?php session_start(); /*header stuff */ ?>

that will be fine, for people who have javascript enabled! but everyone else will have problems

 

quick problem example's

header("Location: login.php"); //will redirect
echo "Hello"; //won't display

 

echo "Hello"; //will display
header("Location: login.php"); //will fail
echo "Hello"; //will display

 

Hello
<?php
header("Location: login.php"); //will fail
echo "Hello"; //will display
?>

 

as you can see ANY output will cause the header to fail..

if you post your code (in code tags) I'm sure someone give you a better option

thanx, one more question...how do users know that their javascript is enabled or disabled???

Many ways.. I normally use some JavaScript to detect if its on.

 

and which browsers disable the use of javascript??

its an option in all browsers.

 

ha...ha...ha...ha... yeah this is what i want to do

let say

 

in page1.php, i have a form and once submit button was clicked then it will go to page2.php.

 

page2.php only will be used as a page to run Delete query , so i only put Delete query... n it immediately goes back to page1.php after all queries have been executed...

 

that's why i put header('locationXXXXXXXXXXXX after i run mysql_query("DELETE FROM xxxxxxxxxxxxxxxxxxxxxxxxxx

 

n it goes ERRROOORRRRRR ::)

 

okay.. first off, I wouldn't post to page2.php i would post to page1.php and have an if statement to capture the request..

ie

<?php
if(!empty($_POST['DELETE']))
{
  $ID = (int) $_POST['DELETE'];
  //DELETE FROM table where ID= $ID
}
?>
//form here

 

but could you post your page2.php

okay this is the code

 

<?php session_start();?>

<?php require_once('configuration.php');?>

<?php $user=$_SESSION['user'];

$id=$_GET['id'];

$query="DELETE FROM table WHERE user='$user' AND id='$id'";

$sqlquery=mysql_query($query);

 

print "<script>";

print "self.location='page2.php'";

print "</script>";

 

 

For that short bit of code, finding and eliminating the output that is causing the header error would be simple, except that it would take seeing the actual error message as that states where the output is occurring at. xxxxx out any sensitive information in the error message, but you have got to supply all the relevant information if you want someone else to help find the cause of the problem.

try this

<?php session_start();
require_once('configuration.php');
$user=$_SESSION['user'];
$id=(int)$_GET['id'];
$query="DELETE FROM table WHERE user='$user' AND id='$id'";
$sqlquery=mysql_query($query);
header("Location: page2.php");

 

have NOTHING before the <?php (including a space or return)

also update

table

to the table name

 

EDIT: oops missed a ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.