Below is some code to use as a starting point for completing this
assignment.
<!--
Your Name
CS 4312
Lab 08
-->
<?php
/* Check the protocol for this request. Redirect an HTTP request to
an HTTPS request.
Ref.: https://stackoverflow.com/questions/5106313/redirecting-from-http-to-https-with-php
*/
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off")
{
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Lab 08</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<p>
<?php
echo "Your Name - CS 4312 - Lab 08<br /><br />\n";
// Obtain the data following the ? in the URL via which the page was
// accessed.
$argv = $_SERVER['QUERY_STRING'];
// Decode any occurrences of %## in the given string. For example, if URLs
// contain spaces when sent to a server, they are transformed into
// %20. The two characters following % are considered hexadecimal
// values and represent the character's ASCII code. 20 hex is equal to
// 32 decimal, the ASCII representation for a space character.
$argv = urldecode($argv);
if (strlen($argv) == 0)
{
echo "This script expects an argument with a length of at least " .
"one.<br />\n";
goto end;
}
echo "For the input string<br />\n";
echo "</p>\n";
echo "<pre>\n";
echo $argv . "\n";
echo "</pre>\n";
echo "<p>\n";
echo "the base64 encoded string is<br />\n";
echo "</p>\n";
// ... Put more code here
end:
?>
</p>
<p>
<?php
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$location = urlencode($location);
echo '<a href="https://validator.w3.org/nu/?doc=' . $location . '">';
?>
<img src="https://www.w3.org/QA/Tools/I_heart_validator"
alt="I heart Validator logo" height="31" width="80" />
</a>
</p>
</body>
</html>