Redirect after posting?

I have a php page for submitting a resume. after they click the submit button, they report all messages to mail.php

After sending the mail, I want the user to return to another page on the website (where there is an option to work)

is there any command I can use to redirect to another page after mail.php is executed with his business?

thank

+2


source to share


5 answers


On a related note, one important thing about the PHP header command, you must make sure you run that command BEFORE any content is displayed on the page you run it on, otherwise it won't work.

For example, this will NOT work:

<html>
<head>
</head>
<body>
    Hello world
</body>
<?php header("Location: mypage.php"); ?>
</html>

      



but this will work:

<?php header("Location: mypage.php"); ?>
<html>
<head>
</head>
<body>
    Hello world
</body>
</html>

      

Basically, the header command will only work when used in a PHP script BEFORE any static content or even HTML tags are spit out of the script.

+1


source


This is the standard PHP redirect:

<?php
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: http://www.example.com' );
exit;
?>

      



However, in your case, the 301 redirect line is probably unnecessary. It should be noted that it is required exit

, otherwise the rest of your PHP script will be executed, which you may not need (for example, you can display something if there is an error).

Additionally, the function header

must be called before any output is sent to the browser (including empty lines). If you cannot avoid blank lines, put ob_start();

at the beginning of your script.

+8


source


header("Location: /yourpage.php");

      

PHP Documentation

+5


source


use header () :

header('Location: http://example.com/new_loc/');

      

or

header('Location: /new_loc/'); // if it within the same domain.

      

+2


source


At the end of mail.php just add

header("Location: anotherpage.php");

      

Remember that you cannot output anything before calling header () for the redirect to work properly.

+2


source







All Articles