Closed Thread Icon

Topic awaiting preservation: php redirecting (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22089" title="Pages that link to Topic awaiting preservation: php redirecting (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: php redirecting <span class="small">(Page 1 of 1)</span>\

 
kronk
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jun 2004

posted posted 06-08-2004 02:36

I am still kind of new to this php scripting, but need to know how to redirect someone after they have completed a form, the form gets sent via email (mail(blablabla)) using php, however i have added a line

header("Location:http://the-url-goes-here.com");

exit;

but keep getting error message saying

Cannot modify header information - headers already sent by (output started .....)

any suggestions

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-08-2004 02:47

You need to do the redirection before you have any information sent to the browser.

This means that you need to do the location at the very beginning of your page.

code:
<?php
... some php code ...
header("Location:http://www.somepage.com/");
... maybe some more code ...
?>
<!DOCTYPE...>
<html ...>
<head>
... rest of page ...



You probably have a php code block somewhere in the body of you html. You need to move this code block to the beginning.

This sometimes requires some you to create an extra variable and then to echo that variable later.

Good luck,

kronk
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jun 2004

posted posted 06-08-2004 02:53

is there a way that i can delay the redirection for a few seconds and display a message on the screen before the redirect takes place??? the form will be for customer inquiries and i dont want to give a bad impression

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-08-2004 02:55

For the straight redirection: http://www.php.net/header
For a delayed redirection, you can use either JavaScript, or a REFRESH META TAG.




(Edited by poi on 06-08-2004 02:58)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-08-2004 03:26
code:
<meta http-equiv="refresh" content="10; url=http://www.somesite.com/" />



The meta refresh is generally better than the javascript one because even if the user does not have javascript the meta refresh will work as most browsers understand it.

Just place that bit of code in your header sections and it will redirect to the given url after a delay of seconds which is the number before the url. In the above case the page will refresh after 10 seconds. That is actually a really long time. I think that 5 seconds is about the most a user will want to be on a page that you are going to be taking them away from. And make sure that you give them the "Click Here" option to speed up the process. I get cranky when I have to sit on some page for any amount of time waiting to get to the actual content.

kronk
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jun 2004

posted posted 06-08-2004 04:25

Thanks I went with the meta tag in the header, timed it for 3 seconds. I didnt have to change any other page scripts and everything works the way i wanted. if i have any other dramas i will post here. thanks everyone.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-08-2004 08:56

you could maybe extend these faqs with some advice when to use what, if you had the spare time:

How can I redirect a page with HTML?
How can I redirect a page with JavaScript?
How can I redirect a page with PHP?

(We're still missing an ASP one as well).

oh and about redirecting after some time, please examine this:
php/ http-header redirect with time

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 06-08-2004 21:17

Response.Redirect('adress');

(^-^)b

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-08-2004 21:25

you know... everyone can create a page in the faq. So feel free to add to it.

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 06-08-2004 23:52

I have.
Thanks.

(^-^)b

« BackwardsOnwards »

Show Forum Drop Down Menu