A complicated tutorial. Very useful for a wedding invitation web.
TutorialPHP Redirect Using $GET Parameter
3 April 2023
  • First step, build your index.html. Example:
index.html
<html lang="en" data-bs-theme="dark">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">    
    <title>Invitation</title>    
</head>
<body>
    
    	<form method="GET" action="link.php">
            <div class="container">
                <div class="border rounded-3 p-3">
                    <h1 class="font-estetik text-center mb-3" style="font-size: 3rem;">Invitation</h1>
                    <input type="hidden" id="idbalasan">
                    <div class="mb-1" id="balasan"></div>
                    <div class="mb-3">
                        <label class="form-label">First Name</label>
                        <input name="name" type="text" class="form-control shadow-sm" id="formnama" placeholder="Required" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Middle Name</label>
                        <input name="mname" type="text" class="form-control shadow-sm" id="formnama" placeholder="(Optional)">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Last Name</label>
                        <input name="lname" type="text" class="form-control shadow-sm" id="formnama" placeholder="Required" required>
                    </div>
                    
                    <div class="d-grid mb-2">
                        <button class="btn btn-primary btn-sm rounded shadow" id="kirim">
                            Send<i class="fa-solid fa-paper-plane ms-1"></i>
                        </button>
                    </div>
                </div>
                
            </div>
          </form>

</body>
</html>

Result:

Preview


  • Then create link.php file or whatever, and fill in the file with the code below (adjust it to your needs):
link.php
<html>
<head>
	
        <title>
        PHP REDIRECT FROM SUBMISSION FORM USING GET PARAMETER
        </title>

</head>
<body>

<!-- Start HTML Body/CSS →

<!-- Start Get Parameters 

<?php

$name = $_GET['name'];
$mname = $_GET['mname'];
$lname = $_GET['lname'];

echo "<h2>Click " . "<a href=https://example.com/?to=$name%20$mname%20$lname>" . "here</a>" . " if you are not redirected automatically in: <span id=seconds>5<span></h2>";
?>

<?php
$url;
$time = 5500; // time in milliseconds
switch ($_GET['name']) {
        case '':
                default:
                $url = "https://example.com";
        break;
}
?>

<!-- End Get Parameters 

<!-- Start Redirect 

<script type="text/javascript">
        setTimeout("window.location='<?php echo $url . "/?to=$name" . "%20" . "$mname" . "%20" . "$lname"; ?>'", <?php echo $time; ?>);
</script>

<!-- End Redirect -->

<!-- // Start Countdown →

<script type="text/javascript">
var seconds = 5; // seconds for HTML
var foo; // variable for clearInterval() function
function updateSecs() {
    document.getElementById("seconds").innerHTML = seconds;
    seconds--;
    if (seconds == -0) {
        clearInterval(foo);
        redirect();
    }
}
function countdownTimer() {
    foo = setInterval(function () {
        updateSecs()
    }, 950);
}
countdownTimer();
</script>

<!-- // End Countdown →

<!-- End HTML Body/CSS →

</body>
</html>