header("location: http://...");

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

yearling
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Mar 14, 2003 1:07 am

header("location: http://...");

Postby yearling » Wed Apr 02, 2003 1:09 am

Salut à tous,

j'ai juste une petite question à vous poser à propos d'un problème qui arrive fréquemment et dont je ne comprends pas le pourquoi. En fait, j'essaie uniquement de faire une redirection via l'instruction suivante <? header("location: http://..."); ?> et j'obtiens le message d'erreur suivant :

Warning: Cannot add header information - headers already sent by (output started at http://...:8)

Comment puis-je résoudre ce problème et quelle en est la raison ?

Je vous en remercie d'avance ...

Bonne journée ...

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Wed Apr 02, 2003 1:34 am

Òû óæå ïîñëàëà õåäåðè ,èõ íåëüçÿ ïîñûëàòü ïîñëå òîãî êàê òû íàïèøåøü ÷òî òî â áðàóçåðå...

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Wed Apr 02, 2003 5:24 pm

English please.

HighOrbit
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 31, 2003 9:00 pm

Postby HighOrbit » Wed Apr 02, 2003 5:53 pm

I understand enough french to know what you are asking, but I don't know enough french to reply in french. But here is my answer in english.

The error message is because the headers must be sent before any HTML output. So if you have any echo statments or any text, they must go after the header. This error will also be given if you have a parser or syntax error somewhere before the header (because the parser error message gets sent as html before the header is sent).

Osaou
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Apr 15, 2003 4:52 pm
Location: Stockholm, Sweden
Contact:

Postby Osaou » Tue Apr 15, 2003 5:03 pm

First of all:
I understand enough french to know what you are asking...
Riiiight buddy, you don't know a word french, you were just reading his error message, that's what I say... ;)

But anyway... There is a way to keep php from sending all parsed material directly...

Code: Select all

ob_start();

If you call the above function at the top of the page, the parsed info will only be "flushed" (sent to the user) when the buffer exceeds its storage limit, at the end of the page, or when you command it to...

Happy php-ing... =)

This way you can use functions such as header() to send the user to another page when the script has already sent some html code...

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

headers first!!

Postby ruturajv » Tue Apr 15, 2003 11:56 pm

It is necessary to send any HTTP headers before you write any html

eg if you write

Code: Select all

echo('something');
header('location: http://somethihg');


This will create a error
hence do not write any html tag before the header info

Code: Select all

<?php
header('location: http://somethihg');


Oromian
New php-forum User
New php-forum User
Posts: 38
Joined: Fri Apr 04, 2003 2:44 pm
Location: Canada
Contact:

Postby Oromian » Wed Apr 16, 2003 4:04 am

http://www.altavista.com

translate! :roll:


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest