PDA

View Full Version : Cannot modify header information



nigelwong
November 9th, 2005, 01:32
hi, i wouldl ike to place some javascript after a PHP Form.

So, i please the code after the <? ?> script

But it says Cannoy modify header information etc. even though the scripts work perfectly

How can i do this? Is there some code i can insert after the php code to link to a remote page where the javascript is inserted? Thankyou for your help/

themoose
November 9th, 2005, 11:36
<?php include ("path/to/javascript/page") ?>

or just put

include ("path/to/javascript/page")

nigelwong
November 10th, 2005, 02:41
I tried, it still gives an error.. will require "path" work?

ciprian@terra-bit
November 10th, 2005, 05:17
Hey there

Is your Javascript code outputting anything to the browser ? Even if it's not, the browser will concider it as MARKUP output.

THEREFORE the solution to this is simple:

Put the PHP code ABOVE the javascript code and ABOVE ANY OTHER html/javascript code. Apparently your PHP code contains either session_start or other session functions OR the header function which HAVE to be placed ABOVE ANY OTHER piece of code in the page. They HAVE to be parsed FIRST in ANY web page. (More info at: http://ro2.php.net/header)
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
?>

The error will go away IF you put the PHP code BEFORE any other code in your page and NOT after.

Thanks
Hope this helps

ryza
November 12th, 2005, 23:05
you cant output text infront of header information.