tags:

views:

27

answers:

1

Error I tried this page to run on local, it is running perfectly fine but showing me a warning on uploading. What might be the reason.

I used session as per given in w3schools..

The session_start() function must appear BEFORE the tag

+1  A: 

You should not write any data to the response body before invoking PHP functions which may modify the response headers.

For example, do not do:

<!doctype html>
<?php session_start(); ?>
...

but rather do

<?php session_start(); ?>
<!doctype html>
...

The session_start() may need to set a cookie in the response header. That's only possible if the response body has not been sent/flushed yet. Why it works in local environment is probably because the response buffer is larger there (server-dependent configuration). Regardless of the buffer size, you should always do this kind of tasks, which possibly modifies the response headers, in the very top of the PHP file, before any character is been written to the response body.

BalusC
@BalusC do u mean to say <?php session_start(); ?> must be the first line of the page ?
Shantanu Gupta
That's correct. It's by the way "you", not "u".
BalusC
@BalusC: I changed it. It is still not working. Please check what's an issue
Shantanu Gupta
It were two errors. You've fixed only one. There's still another one which is trying to modify the headers after the response has been committed. Check line 6. The source code learns me that it's emitted *after* doctype, html and body tags. This is still wrong. It should happen *before* them all.
BalusC