![]() |
php form header location problem
hi
i've got a form on a webpage http://www.domain.com/contact.htm but when it is submitted rather than the page redirecting to the thanks.htm page, the thanks.htm page just shows up on top of the contact.htm page. any idea what i'm doing wrong? btw the form does send the email its just this redirection that is a problem. below is the code i'm using. if($send) {header("Location: http://www.domain.com/thanks.htm"); exit(); } else {print "We encountered an error sending your mail"; } exit(); } anyone got any ideas? thanks in advance |
Hard to tell with what you posted, would have to see the form and rest of the page(s).
I cleaned this up a bit: Code:
if(isset($send)) { |
I'm just off to bed but i'll give that a try in the morning. Thanks for your help
|
The code should do the same thing, I didn't really change anything overly important, just easier to read. Would have to see the rest of your stuff to see the issue.
|
Actually it's good practice to have an exit after a header redirect, as in the code he posted, and you removed it. Also why did you add isset?
|
Quote:
|
need to see entire code...
|
Haven't see the exact problem before - but strange things happen if you have anything (even a space or line-break) before the header redirect. It has to be the FIRST thing sent to the browser.
|
Quote:
$send is probable $_POST['send'] unless you have register_globals = on which you really shouldnt :-) Edit; Just thought of that $send might be the return of the mail(); function, in that case ignore my reply. You say you want to include the thanks.html code at the top of your form, yet you use a header('location: ') statement. You are probably looking for an include('url'); statement no? |
He/She probably has
if (Form is Good) $send = 1; else $send = 0; or something to that effect above this code? So you wouldn't want to do isset, the if ($send) is better |
Quote:
Your first if($send) doesn't do anything. Like Zoxxa pointed out, it has to be either if(isset($send)) or if("$send" == "something") :2 cents: |
hi guys
thanks very much for all the advice. i've added the isset although that didn't help my problem. i'm not sure if i explained it very well. upon succesful form submit i want the surfer to be redirecte3d to the thanks.htm page. however currently rather than redirect the thanks.html page weirdly lays on top of the contact htm page so that you can see both in the same window. this is the code i'm using PHP Code:
can anyone see what's wrong with my code? thanks in advance |
Your code is not secure by the way. It may cause you issues. People could use your email script to spam others using your server. Your have to filter your POST variables
Here is what you are looking for: if($send === TRUE) {header("Location: http://www.mydomain.com/thanks.html"); exit(); } |
thanks, that still gave the same error, not sure why. i've now given up and i'm modifying someone elses form (which is more secure). thanks again
|
Roly, your error is not an error, it's a notice. You can turn down the error reporting level in php.ini. Your header redirect isn't working because the error is outputting before the header() line, and you cannot send anythign to the output buffer before header().
ini_set('display_errors', 'Off'); |
Quote:
understood, although that variable wasn't getting passed which was the problem. i added the error reporting to try and help diagnose my problems. anyhow i gave up on this and i've got something else working now. thanks anyway |
All times are GMT -7. The time now is 12:55 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123