tags:

views:

530

answers:

5

I have a php page for submitting resumes. once they click submit they info all posts to mail.php

once the mail is sent i would like the user to go back to a different page on the website (where the job opportunity are located)

is is there any sort of command i can use to redirect to a different page after the mail.php is done with its business??

Thanks

+2  A: 
header("Location: /yourpage.php");

PHP Documentation

mnml
+4  A: 

This is a standard redirection in PHP:

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

However, in your case the 301 redirection line is probably not necessary. It should be noted that the exit is necessary, otherwise the rest of your PHP script will be executed, which you may not want (e.g. you may want to display something if there is an error).

Also, the header function must be called before any output is sent to the browser (including blank lines). If you're unable to avoid some blank lines, put ob_start(); at the start of the script.

DisgruntledGoat
Should really be "302 See Other" OR "200 OK" for the status code depending on the situation. 301 status means that the page that was accessed is now in a new location, which is not the case. For more info about using proper status codes, see the references: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Kevin Peno
In this case it should actually be a 303, since data was posted.header("Location: http://www.example.com",true,303);
Alex JL
+1  A: 

use header() function:

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

or

header('Location: /new_loc/'); // if it's within the same domain.
Michal M
+1  A: 

At the end of mail.php just add

header("Location: anotherpage.php");

Remember that you can't output anything before the header() call for the redirect to work properly.

Davide Gualano
A: 

On a related note, one important thing about the PHP header command, you must make sure that you run this command BEFORE any content is displayed on that page you are running it on, or else it will not 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 ever work if it is used in the PHP script BEFORE any static content or even HTML tags are spit out of the script.

Jakobud
And, if you don't want to display html or execute code after the redirection, be sure to add exit(); or die(); before the rest of the page.
Alex JL