I am attempting to use preg_replace to purge everything except letters and numbers in the $_POST, however is seems to be failing to work.
Sample code below demonstrating the problem.
<html>
<?php
if( isset($_POST["name"]) || isset($_POST["age"]) )
{
$x1 = preg_replace('[^A-Za-z0-9]', "", $_POST['name'] );
$x2 = preg_replace('[^A-Za-z0-9]', "", $_POST['age'] );
$_POST['name'] = $x1;
$_POST['age'] = $x2;
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
}
else{
$_POST['name'] = 'null';
$_POST['age'] = 'null';
}
?>
<body>
<form action="<?php $_PHP_SELF ?>" method="POST" onsubmit=" ">
<br>
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>