How can one implement a 301 redirect from a short URL to the full URL using PHP?

When a short URL needs to be redirected to a full URL using a 301 redirect, we can achieve this by using PHP header() function. This function sends a raw HTTP header to the client, which includes the HTTP status code for a permanent redirect (301) along with the Location header specifying the full URL to redirect to.

<?php
$shortURL = "http://example.com/short";
$fullURL = "http://example.com/full";

header("HTTP/1.1 301 Moved Permanently");
header("Location: $fullURL");
exit();
?>