Skip to content

Instantly share code, notes, and snippets.

@lucasburlingham
Created January 11, 2024 17:53
Show Gist options
  • Save lucasburlingham/20e569c74761e62333ed12aceb96e7ad to your computer and use it in GitHub Desktop.
Save lucasburlingham/20e569c74761e62333ed12aceb96e7ad to your computer and use it in GitHub Desktop.
Singlepage SHA256 calculator in PHP using htmx
<?php
if(isset($_REQUEST["string"])) {
printf(hash("sha256", $_REQUEST["string"]));
} else {
printf("No string provided in request. Please provide a \"string\" to hash. POST & GET are supported.");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SHA256 Calculator</title>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST">
<hr>
<label for="string">Input string:</label>
<input type="text" name="string" id="string" placeholder="String to hash">
<input type="submit" value="Calculate Hash" hx-post="<?php echo $_SERVER["PHP_SELF"] ?>" hx-swap="outerHTML" hx-target="#output">
</form>
<p><b>Output:</b></p>
<div id="output"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment