473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with header("Location:.. function

Hi,

I am trying to use the following function:

header("Location: http://www.mysite.co.uk/home/update/index.php");

....but getting the following error:

Warning: Cannot modify header information - headers already sent by
(output started at
/data/httpd/VirtualHosts/www/htdocs/home/update/index.php:12) in
/data/httpd/VirtualHosts/www/htdocs/home/update/index.php on line 124
Is there any reason why I am getting this error? One concern of mine
was that the header function was not at the top of the page (line 1),
does this matter? I need this command to run a series of statements and
depending on specific conditions, redirect the user to another page.

Cheers

Burnsy

Jul 17 '05 #1
6 2342
*** bi******@yahoo.co.uk wrote/escribió (7 Jul 2005 03:15:21 -0700):
Warning: Cannot modify header information - headers already sent by
(output started at
/data/httpd/VirtualHosts/www/htdocs/home/update/index.php:12) in
/data/httpd/VirtualHosts/www/htdocs/home/update/index.php on line 124
Is there any reason why I am getting this error?
Nope. You've been chosen randomly for suffering divine wrath :)

May I ask what's in line #12 of
/data/httpd/VirtualHosts/www/htdocs/home/update/index.php file?
One concern of mine was that the header function was not at the top of the page
(line 1), does this matter?


It can be last time of the script if you want to. The only rule you must
follow is that headers come first and content comes later. You cannot mix
them.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2
in other words, you're probably printing something to the screen
before your header command. just put your header command way at the
top.

Jul 17 '05 #3
This is the most commonly asked question in PHP and people keep asking
it. Maybe it's time to add a FAQ to the PHP Manual, I thought there was
already one.

The line number in which you call this does not matter, it can be on
line 1 or on line a million and still work. What does matter is whether
or not output (like html, text...) is sent the browser first. You don't
want that. Your error indicates that output began at around line 12 so
fix that. Or if you're lazy and want to write improper code, enable
output buffering to take care of this. Enabling it allows you to send
headers() throughout your code without a problem.

Jul 17 '05 #4
On 07/07/2005 17:35, Philip Olson wrote:
[Call to header function not 'working'] is the most commonly asked
question in PHP and people keep asking it. Maybe it's time to add a
FAQ to the PHP Manual, I thought there was already one.


There is an FAQ in the manual, but this shouldn't need to be added -
it's clearly addressed in the description of the header function:

"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."

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 17 '05 #5
Philip Olson wrote:
The line number in which you call this does not matter, it can be on
line 1 or on line a million and still work. What does matter is whether
or not output (like html, text...) is sent the browser first. You don't
want that. Your error indicates that output began at around line 12 so
fix that. Or if you're lazy and want to write improper code, enable
output buffering to take care of this. Enabling it allows you to send
headers() throughout your code without a problem.


Alternative solution is to use HTML_Page (HTML_Page2) or similar
mechanism, where you construct an objet to represent a page, and then
print your "body" stuff to it. That way, if you need to redirect mid
way through the script, you are quite sure nothing has been sent. At
the end of the script, just call the "display" function for your object.

/m
Jul 17 '05 #6
Yes but it's asked all the time and newbies don't understand what that
means. Anyway, I'll add this FAQ this week.

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dave Smithz | last post by:
Hi there, I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g. if...
5
by: Duderino82 | last post by:
I'm working on a very simple peace of php where basically there is a form and 3 buttoms. One refreshed the page, one posts the form, and another one (since this form contains values of a record)...
1
by: hemingvej45 | last post by:
Session variables set before a header("Location: whatever") are not being written. And yes, before the header() call, I have session_write_close() but the result is the same. This problem is...
6
by: dhillarun | last post by:
Hi everybody, I displaying file download window("save-as dialog box") using PHP "header()" function. How to track that user have clicked "save" button or "cancel" button???
3
by: thomasg | last post by:
Hi, I am moving some scripts from a UNIX box to a Windows box. A data entry form calls a PHP script the updates the records from the form. After the script completes, The script redirects to...
2
by: hagenaer | last post by:
Hello, I'm building a simple shopping cart to work with PayPal. I'd like to have the user post his basket to my page, validate the input, then redirect him _with his validated form data_ to...
4
by: andre rodier | last post by:
Hello, I need to display or propose a jpeg image on a web page. When I need to display the image, I use this code : header("Content-Length: $fileSize") ; header("Content-Type: $type") ;...
6
by: webgenius | last post by:
I'm designing a small site and I have this structure in mind: index.php --------------- login fields. User enters login info. LoginCheck.php is called. LoginCheck.php -----------------------...
5
bilibytes
by: bilibytes | last post by:
hi, i am making a website with php OOP. i have a class called session: it has the attribues -logged_in; -user_name; -user_ip; -user_level;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.