fl00d
09-01-2007, 02:29 AM
Hi,
I would like to clear the variable contents after my script has processed to stop people from refreshing the page and spamming my database. What happens is that I have info that is passed through a form, and when its all done you can still refresh the page and resubmit the data. I would like to have the variables cleared at the end of the script so that if a person refreshes the page, the error for an empty field will show up because the variables have been cleared.
I've though of just doing something like:
<?php
$blah = $_POST['blah'];
$food = $_POST['cookie'];
$sql = mysql_query...
if($sql){
//insert...
}
//clear variables
$blah = "";
$food = "";
?>
To check for blanks I implement this:
<?php
$blanks = array();
if(empty($name)){
$blanks[] = "Error no name...";
}
if(empty($food)){
$blanks[] = "Error no food...";
}
if(!empty($blanks)){
foreach($blanks as $error){
echo $error;
}
}
?>
Does anyone have a more efficient method for clearing the variables?
*EDIT*
I just thought about unset(), what about that?
I would like to clear the variable contents after my script has processed to stop people from refreshing the page and spamming my database. What happens is that I have info that is passed through a form, and when its all done you can still refresh the page and resubmit the data. I would like to have the variables cleared at the end of the script so that if a person refreshes the page, the error for an empty field will show up because the variables have been cleared.
I've though of just doing something like:
<?php
$blah = $_POST['blah'];
$food = $_POST['cookie'];
$sql = mysql_query...
if($sql){
//insert...
}
//clear variables
$blah = "";
$food = "";
?>
To check for blanks I implement this:
<?php
$blanks = array();
if(empty($name)){
$blanks[] = "Error no name...";
}
if(empty($food)){
$blanks[] = "Error no food...";
}
if(!empty($blanks)){
foreach($blanks as $error){
echo $error;
}
}
?>
Does anyone have a more efficient method for clearing the variables?
*EDIT*
I just thought about unset(), what about that?