Hi,
I'm relatively new to PHP. I'm planning to use this code on every page on my site. It sets up variables based on whatever is posted in from the form.
I want to do this as I've developed the site on another box and it doesn't work on a new box I think because register_globals is off.
I'm aware that anyone can post anything to the php code and am worried that they will be able to post something naughty and mess me up, is this the case?:
Thanks.
<?PHP
function make_safe($value)
{
if( get_magic_quotes_gpc() )
{
$value = stripslashes( $value );
}
if( function_exists( "mysql_real_escape_string" ) )
{
$value = mysql_real_escape_string( $value );
}
else
{
$value = addslashes( $value );
}
return $value;
}
?>
<?PHP
foreach ($_POST as $variable_name => $variable_value)
{
${$variable_name} = make_safe($variable_value);
}
echo $name . '<br />';
echo $age . '<br />';
?>
<form METHOD="POST">
<input type="text" name="name">
<input type="text" name="age">
<input type="submit" name="submit" value="submit">
</form>