GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php form header location problem (https://gfy.com/showthread.php?t=1081144)

roly 09-11-2012 05:16 PM

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

Zoxxa 09-11-2012 05:25 PM

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)) {
        header("Location: http://www.domain.com/thanks.htm");
} else {
        echo "We encountered an error sending your mail";
}
 
// Everything below this is useless unless there is more code not shown.
exit();
}


roly 09-11-2012 05:28 PM

I'm just off to bed but i'll give that a try in the morning. Thanks for your help

Zoxxa 09-11-2012 05:30 PM

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.

helterskelter808 09-11-2012 05:42 PM

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?

Zoxxa 09-11-2012 05:51 PM

Quote:

Originally Posted by helterskelter808 (Post 19183480)
Actually it's good practice to have an exit after a header redirect, as in the code he posted, and you removed it.

Yep, I wasn't really thinking.

EDepth 09-11-2012 06:48 PM

need to see entire code...

shake 09-11-2012 06:56 PM

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.

AdultEUhost 09-11-2012 07:24 PM

Quote:

Originally Posted by Zoxxa (Post 19183461)
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)) {
        header("Location: http://www.domain.com/thanks.htm");
} else {
        echo "We encountered an error sending your mail";
}
 
// Everything below this is useless unless there is more code not shown.
exit();
}


Hey Ian,

$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?

KillerK 09-11-2012 11:12 PM

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

CHMOD 09-12-2012 12:49 AM

Quote:

Originally Posted by roly (Post 19183446)
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



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:

roly 09-12-2012 01:34 AM

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:

error_reporting(E_ALL); ini_set('display_errors''On'); 
ini_set("sendmail_from""[email protected]"); 
$email_to "[email protected]"
$from $_REQUEST['email'];
$headers "From: $from"
$email_subject "Web Contact Data"

$name $_POST['name'];  
$email $_POST["email"];  
$email_message $_POST["message"]; 
$from $_POST["email"]; 
$phone $_POST["phone"];

$company $_POST["company"];


$email_message "We have received the following message:\n\nName: " $name "\r\nEmail: " $email "\r\nPhone: " $phone "\r\nCompany: " $company "\r\nMessage: " $email_message;



if(
$from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if(
$name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send mail($email_to$email_subject$headers$email_message"[email protected]"); 

if(isset(
$send)) 
{
header("Location: http://www.mydomain.com/thanks.html");
exit();

else 
{echo 
"We encountered an error sending your mail, please notify [email protected]";} 
exit();
}


one other problem that i can't see where its wrong is that it i get the error "Notice: Undefined variable: phone in /home/admin/domains/mydomain.com/public_html/contact.php on line 19 however as far as i can see i've defined what phone is?

can anyone see what's wrong with my code?

thanks in advance

CHMOD 09-12-2012 01:55 AM

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();
}

roly 09-12-2012 05:11 AM

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

k0nr4d 09-12-2012 05:43 AM

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');

roly 09-12-2012 01:27 PM

Quote:

Originally Posted by k0nr4d (Post 19184325)
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');

hi konrad

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