Skip to content

Instantly share code, notes, and snippets.

@azwan082
Created August 14, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azwan082/2b1a20b9b293b1937e6e6dc6849959c5 to your computer and use it in GitHub Desktop.
Save azwan082/2b1a20b9b293b1937e6e6dc6849959c5 to your computer and use it in GitHub Desktop.
Simple PHP script to test for validity of serialized values
<?php $unserialized = null; ?>
<h1><a href="test_serialize.php">Test PHP unserialize</a></h1>
<form action="test_serialize.php" method="post">
<p>
Unserialize: <?php
if (isset($_POST['v'])) {
$v = unserialize($_POST['v']);
if ($v) {
$unserialized = $v;
echo '<span style="color:green">Success</span>';
}
} ?>
</p>
<p>
<textarea name="v" style="width:800px;height:300px;"><?php if (isset($_POST['v'])) { echo htmlentities(trim($_POST['v'])); } ?></textarea>
</p>
<p>
Length: <?php if (isset($_POST['l'])) { echo strlen(trim($_POST['l'])); } ?>
</p>
<p>
<textarea name="l" style="width:800px;height:150px;"><?php if (isset($_POST['l'])) { echo htmlentities(trim($_POST['l'])); } ?></textarea>
</p>
<p><button type="submit">Submit</button></p>
<?php if ($unserialized) { echo '<p>Unserialized: <pre>'; echo var_export($unserialized, true); echo '</pre></p>'; } ?>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment