howdy yo!
i had a quick question, if yous dont mind? 😃

i am trying to get my page to redirect to another page once a script executes. kinda like a meta refresh but to a differnt page. what is need is this redirect to fit in this code:

<?
if($HTTP_POST_VARS['submit']) {
	if ($select2 == "13") {
		mail ($to_myself, $subject, $message);
********  Need the redirect code to go here  **********
	}
}
?>

what i would like to accomplish is AFTER it mails me all the info i have setup, i would like it redirect to a new page, one that is off my site.

any ideas?
thanks!

    look into

    [man]header[/man]("Location: htp://somewhere/off/my/site");

      thats the first thing i tried but it would let me do it, i kept getting an error:

      Warning: Cannot add header information - headers already sent by (output started at \tested\file2.php:29) in \tested\file2.php on line 52

      this is what i used:

      <?
      if($HTTP_POST_VARS['submit']) {
      	if ($select2 == "13") {
      		mail ($to_myself, $subject, $message);
      		header("Location: htp://www.server.com/index.php");
      	}
      }
      ?>
      

      and that all there is inside my <body> tag. i also did notice the extra 't' missing from the htp://. 😉.

      any other ideas?

        it has to come before your </head> tag

          thats what i figured but the thing is i have 'stuff' on the webpage. what it is is theres a form the veiwer has to fill out, then once the hit the submit button, i need it to email me the informaion from the form, then redirect them to a new page. so there is stuff going on on the page other then just the redirect.

            header redirection is intant it doesnt load a page before it sends to the next page just stick the php at top of the script and you should be fine
            use this code to insure the page does not load

            if($HTTP_POST_VARS['submit']){
            
            if ($select2 == "13"){
            
            mail ($to_myself, $subject, $message);
            
            header("Location: htp://www.server.com/index.php");
            exit;
            }
            
            }
            
            

              i pasted that exact code into my <head>, changing the location url around. still i am getting errors. if you would like, here is the page to view:
              http://www.static22.com/tested/file2.php
              you can fill out the form, then hit the submit button, you'll see the error.

                hmm ok it has to be above the <html> tag i think ive never had this problem with header() but it happends with setcookie which has to be above <html> so try that

                  😕
                  i have tried it everywhere on the page at one time; above the html, in the head, in the body, as a footer. keep getting the same error...

                  maybe i can email you the file, so you could look through it? maybe something is keeping it from working right?

                    try using:

                    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=YourUrl.php\">";

                    instead of:

                    header("Location: htp://www.server.com/index.php");

                    Note that the \ is used to escape the double quotes inside the <META> tag.

                    Hope this helps

                      Also try:

                      if($submit)

                      instead of:

                      if($HTTP_POST_VARS['submit'])

                        using if($submit) is highly unsecure and is not recommended what he has done is right, also in version 4.2.3 you cant use just $submit you have to go like this:

                        $get_var = $GET['var'];
                        $post_var = $
                        PUT['var'];

                        you can also use $HTTP_POST_VARS or $HTTP_GET_VARS instead of $get, $put

                          this could work.. i think?

                          if($HTTP_POST_VARS['submit']){
                          
                          if ($select2 == "13"){
                          
                          mail ($to_myself, $subject, $message);
                          
                          
                          header("Location:h ttp://www.offsiteserver.com/directory/index.php");
                          echo
                          "<html>
                          <head><title>Re-Direction Page</title>
                          </head>
                          <body>";
                          
                          echo "Re-directing...";
                          exit;
                          }
                          
                          }
                          

                            i used the following and it works fine:

                            if(isset($_POST['submit'])){
                            
                            if ($select2 == "13"){ //i dont know what this is here for.....
                            
                            mail ($to_myself, $subject, $message);
                            
                            header("Location: [url]https://www.server.com/index.php[/url]");
                            exit;
                            }
                            
                            }
                            
                            ?>
                            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                            <html>
                            <head>
                            <title>createHome- o

                              Originally posted by dburgessjr
                              i have tried it everywhere on the page at one time; above the html, in the head, in the body, as a footer. keep getting the same error...
                              [/b]

                              DeadlySin3's code is the right way to go about it. Don't send anything to the browser before you send the header() - including blank lines. If you're redirecting them to another page, there's nothing to send anyway.

                              Also it's advisable (generally not necessary, but it can't hurt), to follow it with a call to exit();. Then there's a spot where the script not only finishes, but is seen to finish.

                                you seeem to be confused about what a header is

                                when you send someting across the internet it has a header that says among other things... what type of data it is:

                                text/plain text/html.. etc

                                normally in php all that is written for you and all goes before anything you print out to the screen...

                                header does not affect you html <head></head> tag

                                header lets you set info in the actual http request... before your <html> tag, your <html> tag and everything in it is just the body of you httpd request....

                                if you have written anything out to the screen... even one space.... then php has already fixed and written all headers it will send... you need to be sure to interject with a header() call before you write anyhting.... so it can be added to the list...

                                hope this helps

                                  thanks everyone for all your help, its much appreciated!
                                  Duey helped me out via email and the problem is fixed, now.

                                  thanks again, everyone!

                                    Write a Reply...