diff --git a/app/public/index.php b/app/public/index.php index abd5cfc..c116672 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -25,8 +25,8 @@ $buttons = [ 'serializedtojson' => 'PHP Serialized to JSON', ]; -$str = $result = $_GET['str'] ?? ''; -$action = $_GET['action'] ?? ''; +$str = $result = $_POST['str'] ?? $_GET['str'] ?? ''; +$action = $_POST['action'] ?? $_GET['action'] ?? ''; $plain = str_contains($_SERVER['HTTP_ACCEPT'] ?? '', 'text/plain'); $help = 'https://www.php.net/manual/'; $jsonEncodeOptions = JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES; @@ -121,7 +121,7 @@ if ($action == 'reset') { } elseif ($action == 'serializedtojson') { $stdClass = preg_replace('~O:[0-9]+:"[^"]+"~', 'O:8:"stdClass"', $str); - $unserialized = @unserialize($stdClass); + $unserialized = unserialize($stdClass); if ($unserialized === false) { $result = 'Input text couldn\'t be unserialized: '."\n\n".(error_get_last()['message'] ?? 'Unknown error.'); } else { @@ -156,7 +156,7 @@ if ($plain) { -
+
$label) { ?> @@ -169,9 +169,11 @@ if ($plain) {
- +
+ + diff --git a/app/public/js/form.js b/app/public/js/form.js new file mode 100644 index 0000000..f019cf0 --- /dev/null +++ b/app/public/js/form.js @@ -0,0 +1,21 @@ + +(function() { + const form = document.getElementById('form'); + const textarea = document.getElementById('str'); + + // Change the form method between GET and POST based on the textarea length + const updateFormMethod = () => { + const maxLength = 1024; + const textLength = textarea.value.length; + console.log(textLength); + + if (textLength > maxLength) { + form.method = 'post'; + } else { + form.method = 'get'; + } + } + + document.addEventListener('DOMContentLoaded', updateFormMethod); + textarea.addEventListener('input', updateFormMethod); +})();