Rob Stumpf
Rob Stumpf

Reputation: 1

PHP: Redirecting upon a true statement

Probably something simple I'm missing, but what I'm trying to do is finish up a registration form and after it sends a confirmation email, redirect it to another page. What I have so far

if($sentmail){
<redirection code>
}
else {
echo "Problem sending information, please resubmit.";
}

Upvotes: 0

Views: 58

Answers (3)

hakre
hakre

Reputation: 197775

The most easy redirect call is http_redirect in PHP. Does everything you need to do for a redirect.

if ($sentmail)
{    
    http_redirect('new location');
}
else
{
    echo "Problem sending information, please resubmit.";
}

Upvotes: 0

Mob
Mob

Reputation: 11098

You do this by using the header(); function.

if($sentmail){
     header("Location: http://mypage.com/redirect.php");
     die();
}
else {
     echo "Problem sending information, please resubmit.";
}

Use die(); to stop script execution. Though the page redirects, the script still executes.

Upvotes: 0

Jared Farrish
Jared Farrish

Reputation: 49208

You want header(), and possibly an exit to stop processing.

if ($sentmail) {
    header('Location: http://example.com/after_true_statement_redirected');
    // exit; ???
} else {
    echo "Problem sending information, please resubmit.";
}

Upvotes: 1

Related Questions