Redirect to previous page with php



PHP Snippet 1:

header('Location: ' . $_SERVER['HTTP_REFERER'])

PHP Snippet 2:

<?php
if($_POST["submit"]) {

    $recipient="[email protected]";
    $subject="Form to email message";
    $sender=$_POST["firstname"];
    $senderlast=$_POST["lastname"];
    $senderemail=$_POST["senderemail"];
    $header = "MIME-Version: 1.0" . "\r\n";
    $header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $header .= 'From: $sender <$senderemail>' . "\r\n";
    $message=$_POST["message"];
    $mailBody="First Name: $sender\nLast Name: $senderlast\nEmail: $senderemail\n\nMessage: $message";


    if(mail($recipient, $subject, $mailBody, $header)){

        header('Location:contact-us.html'); /*Something Wrong?*/
    }
}

PHP Snippet 3:

echo "<script>window.location.href('contact-us.html');</script>";

PHP Snippet 4:

<?php
    $_SESSION['previous'] = 'http://'. $_SERVER[HTTP_HOST]. $_SERVER[REQUEST_URI];

PHP Snippet 5:

<?php
    if ($_SESSION['previous'] !== '') {
        header('Location: '. $_SESSION['previous']);
    }

PHP Snippet 6:

header('Location:  contact-us.html'); /*Something Wrong?