Possible Duplicate:
How to properly escape html form input default values in php?
I am currently using:
if (isset($_GET['b']))
{
$bb = $_GET['b'];
echo 'found';
}
else
{
$bb = 'white';
echo 'notfound';
}
and
<body bgcolor="<?php echo $bb; ?>">
to allow the users to set the color of the page, what would be the safest method to avoid injection?
Assuming you are expecting a color, you could use a regex for hexadecimal colors:
and the list of the 17 standard colors: aqua, black, blue, fuchsia, gray, grey, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow: