Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2020 13:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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">
Unserialize: <?php
if (isset($_POST['v'])) {
$v = unserialize($_POST['v']);
if ($v) {
$unserialized = $v;
echo '<span style="color:green">Success</span>';
} ?>
<textarea name="v" style="width:800px;height:300px;"><?php if (isset($_POST['v'])) { echo htmlentities(trim($_POST['v'])); } ?></textarea>
Length: <?php if (isset($_POST['l'])) { echo strlen(trim($_POST['l'])); } ?>
<textarea name="l" style="width:800px;height:150px;"><?php if (isset($_POST['l'])) { echo htmlentities(trim($_POST['l'])); } ?></textarea>
<p><button type="submit">Submit</button></p>
<?php if ($unserialized) { echo '<p>Unserialized: <pre>'; echo var_export($unserialized, true); echo '</pre></p>'; } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment