How can I stop this error occurring pls?

This is a discussion on How can I stop this error occurring pls? within the PHP Language forums, part of the PHP Programming Forums category; Folks. I have some PHP code on my site at http://www.london-translations.co.uk/quick-quote.php Which ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-04-2004
Pete Bennett
 
Posts: n/a
Default How can I stop this error occurring pls?

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
Reply With Quote
  #2 (permalink)  
Old 10-04-2004
Chris
 
Posts: n/a
Default 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

Reply With Quote
  #3 (permalink)  
Old 10-04-2004
Chris
 
Posts: n/a
Default 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:

>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
>
>}
>


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

Reply With Quote
  #4 (permalink)  
Old 10-04-2004
Chris Hope
 
Posts: n/a
Default Re: How can I stop this error occurring pls?

Pete Bennett wrote:

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


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/
Reply With Quote
  #5 (permalink)  
Old 10-04-2004
nice.guy.nige
 
Posts: n/a
Default OT: Legal status of Quote? (Was: Re: How can I stop this error occurring pls?)

While the city slept, Pete Bennett (pmb1@futureim.demon.co.uk) feverishly
typed...

> 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

[...]

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!


Reply With Quote
  #6 (permalink)  
Old 10-06-2004
Pete Bennett
 
Posts: n/a
Default 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
Reply With Quote
  #7 (permalink)  
Old 10-06-2004
Tony Marston
 
Posts: n/a
Default 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...
> 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



Reply With Quote
  #8 (permalink)  
Old 10-06-2004
Matthias Esken
 
Posts: n/a
Default Re: How can I stop this error occurring pls?

Pete Bennett wrote:

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


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.

> Am I missing something please?


Yes, you are. ;-)

Regards,
Matthias
Reply With Quote
  #9 (permalink)  
Old 10-07-2004
Pete Bennett
 
Posts: n/a
Default Re: How can I stop this error occurring pls?

Folks,

All sorted now - thanks for all your help.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0