PDA

View Full Version : Problem with header("location:file.php")


amir103
02-10-2007, 05:00 PM
Here is a part of a page of code, notice the header("location:../index.php") at the bottom.
<script language="javascript" type="text/javascript">
if (window!= top)
<? $kn_frame_present = '1'; ?>
</script>
<? $kn_poss_decide = 'kn_not_possible';
if ($kn_frame_present == '1') {
$kn_poss_decide = 'kn_possible';
}
if (empty($_SESSION['kn_splash'])) {
$kn_poss_decide = 'kn_possible';
}
elseif ($_SESSION['kn_splash'] == '1') {
$kn_poss_decide = 'kn_possible';
}
$$kn_poss_decide = 'kn_approved';
?>
<? if ($kn_possible = 'kn_approved') {
$_SESSION['kn_return_id'] = '?kn_return=kn_content/1_news.php';
header("location:../index.php");
}
?>

In the header(location:'s current position, i'm recieveing this error:
'Cannot modify header information - headers already sent by (output started at'
I've tried placing the header on the very top of the page, and it worked, which means it doesn't work if its under that small javascript. The javascript is essential though, and decides wether to header or not, so how can I make this work? Is there a trick know to fix this sort of problem?

papa_face
02-10-2007, 05:05 PM
You need to get rid of this somehow. not sure why you are using javascript like this...

<script language="javascript" type="text/javascript">
if (window!= top)
<? $kn_frame_present = '1'; ?>
</script>

ess
02-11-2007, 12:29 AM
This error is usually thrown when you have already outputted contents to the browser.

In order to fix this problem, you should either add the redirection at the top of the page, before outputting the JS script...or...assign the the JS script to a variable...and only output it after the if statement that contains the header(...).

Hope that helps.
Ess