Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I stop this error occurring pls?

Pete Bennett
Guest
 
Posts: n/a
#1: Jul 17 '05
Folks.

I have some PHP code on my site at

http://www.london-translations.co.uk/quick-quote.php

Which allow people to get quotes for translation work. When the form
is submitted control passes to …

http://www.london-translations.co.uk...te-results.php

And everything is fine. The problem is, people seem to be landing
directly on

http://www.london-translations.co.uk...te-results.php

When they do, errors of the following kind appear


Warning: Cannot modify header information - headers already sent by
(output started at \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)
in \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
on line 499

Warning: Cannot modify header information - headers already sent by
(output started at \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)
in \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
on line 500

Is there a way in PHP checking that people have come from
http://www.london-translations.co.uk/quick-quote.php without throwing
errors up .. .ideally I'd like them to be automatically sent to
http://www.london-translations.co.uk/quick-quote.php but a meaningful
message would be better than bombing out like now.

Thanks

Pete Bennett
Chris
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How can I stop this error occurring pls?


It should be possible to check HTTP_REFERER in the $_SERVER array and
redirect based on that. Can't think of the exact code off-hand, but,
something like this at the top of the script should work:

if($_SERVER["HTTP_REFERER"] != "your starting page"){
header("Location:your starting page");
}else{
the rest of the script

}


hth

C

Chris
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How can I stop this error occurring pls?


On Mon, 04 Oct 2004 14:03:55 +0100, Chris <chris.stephens@nez.oc.ku>
wrote:
[color=blue]
>It should be possible to check HTTP_REFERER in the $_SERVER array and
>redirect based on that. Can't think of the exact code off-hand, but,
>something like this at the top of the script should work:
>
>if($_SERVER["HTTP_REFERER"] != "your starting page"){
> header("Location:your starting page");
>}else{
> the rest of the script
>
>}
>[/color]

Just reading the documentation for HTTP_REFERER and it might not be
the best method since some browsers allow it to be disabled or
modified.

Why not send some token data, probably in a hidden form field, from
the first page and check for its existance in the second page,
redirecting to the first page if it doesn't exist?

C

Chris Hope
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How can I stop this error occurring pls?


Pete Bennett wrote:
[color=blue]
> I have some PHP code on my site at
>
> http://www.london-translations.co.uk/quick-quote.php
>
> Which allow people to get quotes for translation work. When the form
> is submitted control passes to …
>
> http://www.london-translations.co.uk...te-results.php
>
> And everything is fine. The problem is, people seem to be landing
> directly on
>
> http://www.london-translations.co.uk...te-results.php
>
> When they do, errors of the following kind appear
>
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
>[/color]
\\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)[color=blue]
> in
>[/color]
\\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php[color=blue]
> on line 499
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
>[/color]
\\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)[color=blue]
> in
>[/color]
\\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php[color=blue]
> on line 500
>
> Is there a way in PHP checking that people have come from
> http://www.london-translations.co.uk/quick-quote.php without throwing
> errors up .. .ideally I'd like them to be automatically sent to
> http://www.london-translations.co.uk/quick-quote.php but a meaningful
> message would be better than bombing out like now.[/color]

The reason for the errors is that you're trying to send a header to redirect
the user *after* you've already sent output to the browser.

eg you're doing something like this:

print "some output here";
header("Location:
http://www.london-translations.co.uk/quick-quote-results.php");

Because you already sent output with the "some output here" line you can't
then send a header to the browser. So you'll need to rearrange the logic on
the page a bit to ensure all your processing happens first, and all the
output second.

From the error messages you have received, it's telling you the output
started at line 2 in the file and that you've tried to add a header at
499/500.

A really quick and dirty solution to your problem is to add ob_start() to
the beginning of the file. This turns output buffering on which means
nothing will be sent to the browser until you flush the buffer, which won't
happen if you redirect to another page. However, it's best to fix your code
than do this.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
nice.guy.nige
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How can I stop this error occurring pls?


While the city slept, Pete Bennett (pmb1@futureim.demon.co.uk) feverishly
typed...
[color=blue]
> Folks.
>
> I have some PHP code on my site at
>
> http://www.london-translations.co.uk/quick-quote.php
>
> Which allow people to get quotes for translation work[/color]
[...]

As an aside, you state that the "quick quote" isn't binding. IANAL, but I
think if you start offering "quotes" and then say they aren't binding, you
could get into tricky water. You would be better offering an "estimate",
which has a different legal status. Like I say, IANAL.

Cheers,
Nige

--
Nigel Moss
http://www.nigenet.org.uk
Mail address not valid. nigel@DOG.nigenet.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy!


Pete Bennett
Guest
 
Posts: n/a
#6: Jul 17 '05

re: How can I stop this error occurring pls?


Folks,

Thanks for all your help so far however I am still baffled. As a test,
I altered my code to look like this...

1. <html>
2. <?
3. header("Location: ../quick-quote-down-wc.html");

In other words, what ever happens later, people should be sent to the
new page right? Unfortunately I still get

Warning: Cannot modify header information - headers already sent by
(output started at \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)
in \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
on line 3

Warning: mail(): SMTP server response: 554 Error: no valid recipients
in \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
on line 793

Surely, the rest of the code should even be read by the computer never
mind be able to kick out errors as people should be sent straight to
the quick-quote-down-wc.html page?

Am I missing something please?

Pete Bennett
Tony Marston
Guest
 
Posts: n/a
#7: Jul 17 '05

re: How can I stop this error occurring pls?


You have not read the manual properly. You cannot send headers after
generating any other output, so drop the <html> line. You should also use
exit() immediately after header().

--
Tony Marston

http://www.tonymarston.net


"Pete Bennett" <pmb1@futureim.demon.co.uk> wrote in message
news:e7100a42.0410052329.1988dbaf@posting.google.c om...[color=blue]
> Folks,
>
> Thanks for all your help so far however I am still baffled. As a test,
> I altered my code to look like this...
>
> 1. <html>
> 2. <?
> 3. header("Location: ../quick-quote-down-wc.html");
>
> In other words, what ever happens later, people should be sent to the
> new page right? Unfortunately I still get
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php:2)
> in
> \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
> on line 3
>
> Warning: mail(): SMTP server response: 554 Error: no valid recipients
> in
> \\nas06ent\domains\l\london-translations.co.uk\user\htdocs\quick-quote-results.php
> on line 793
>
> Surely, the rest of the code should even be read by the computer never
> mind be able to kick out errors as people should be sent straight to
> the quick-quote-down-wc.html page?
>
> Am I missing something please?
>
> Pete Bennett[/color]


Matthias Esken
Guest
 
Posts: n/a
#8: Jul 17 '05

re: How can I stop this error occurring pls?


Pete Bennett wrote:
[color=blue]
> 1. <html>
> 2. <?
> 3. header("Location: ../quick-quote-down-wc.html");[/color]

Two errors and one bad line.

1. You're having output in line 1 (<html>) before you try to write the
header. This won't work.
2. You're using short tags. <?php would be better and will run anywhere.
3. You're using an invalid location. The Location-header needs an
absolute URI. For details have a look at the manual at
http://www.php.net/header.
[color=blue]
> Am I missing something please?[/color]

Yes, you are. ;-)

Regards,
Matthias
Pete Bennett
Guest
 
Posts: n/a
#9: Jul 17 '05

re: How can I stop this error occurring pls?


Folks,

All sorted now - thanks for all your help.
Closed Thread