php form header location problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roly
    Confirmed User
    • Aug 2002
    • 1844

    #1

    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
    Confirmed User
    • Feb 2011
    • 1026

    #2
    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();
    }
    [email protected]
    ICQ: 269486444
    ZoxEmbedTube - Build unlimited "fake" tubes with this easy 100% unencoded CMS!

    Comment

    • roly
      Confirmed User
      • Aug 2002
      • 1844

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

      Comment

      • Zoxxa
        Confirmed User
        • Feb 2011
        • 1026

        #4
        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.
        [email protected]
        ICQ: 269486444
        ZoxEmbedTube - Build unlimited "fake" tubes with this easy 100% unencoded CMS!

        Comment

        • helterskelter808
          So Fucking Banned
          • Sep 2010
          • 3405

          #5
          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?
          Last edited by helterskelter808; 09-11-2012, 04:51 PM.

          Comment

          • Zoxxa
            Confirmed User
            • Feb 2011
            • 1026

            #6
            Originally posted by helterskelter808
            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.
            [email protected]
            ICQ: 269486444
            ZoxEmbedTube - Build unlimited "fake" tubes with this easy 100% unencoded CMS!

            Comment

            • EDepth
              Confirmed User
              • Nov 2005
              • 510

              #7
              need to see entire code...
              ICQ: 275335837

              Comment

              • shake
                frc
                • Jul 2003
                • 4663

                #8
                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.
                Crazy fast VPS for $10 a month. Try with $20 free credit

                Comment

                • AdultEUhost
                  ORLY?
                  • Oct 2005
                  • 2579

                  #9
                  Originally posted by Zoxxa
                  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?
                  Last edited by AdultEUhost; 09-11-2012, 06:33 PM.
                  ICQ: 267-443-722 / leon [at] adulteuhost [dotcom]

                  Nominated for an XBIZ Award as "Webhost of the Year" in 2007, 2012, 2013 and 2014

                  Comment

                  • KillerK
                    Confirmed User
                    • May 2008
                    • 3406

                    #10
                    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

                    Comment

                    • CHMOD
                      Confirmed User
                      • Jun 2003
                      • 1697

                      #11
                      Originally posted by roly
                      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")

                      Sell our Silicone Dolls and make big money!

                      Our website:
                      https://www.sexdolls-shop.com/

                      Signup:
                      http://www.sexdollscash.com/sliiing/registration.php

                      Contact:
                      [email protected]

                      Comment

                      • roly
                        Confirmed User
                        • Aug 2002
                        • 1844

                        #12
                        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
                        Last edited by roly; 09-12-2012, 12:38 AM.

                        Comment

                        • CHMOD
                          Confirmed User
                          • Jun 2003
                          • 1697

                          #13
                          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();
                          }
                          Sell our Silicone Dolls and make big money!

                          Our website:
                          https://www.sexdolls-shop.com/

                          Signup:
                          http://www.sexdollscash.com/sliiing/registration.php

                          Contact:
                          [email protected]

                          Comment

                          • roly
                            Confirmed User
                            • Aug 2002
                            • 1844

                            #14
                            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

                            Comment

                            • k0nr4d
                              Confirmed User
                              • Aug 2006
                              • 9231

                              #15
                              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');
                              Last edited by k0nr4d; 09-12-2012, 04:44 AM.
                              Mechanical Bunny Media
                              Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

                              Comment

                              • roly
                                Confirmed User
                                • Aug 2002
                                • 1844

                                #16
                                Originally posted by k0nr4d
                                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

                                Comment

                                Working...