12th page of secure use of php form submission program. It is used to display error information and success Information. In fact, you can also directly echo the error information. here I just want to see the highlights of my error information page and define a function for page output. It is used to display error information and success Information. In fact, you can also directly echo the error information. here I just want to see the highlights of my error information page and define a function for page output.
The code is as follows:
// Savecomment. php // do not read comments first. after reading this article, let's look back.
Require ("config. php ");
Mysql_connect ($ servername, $ dbusername, $ dbpassword) or die ("database connection failed ");
$ Name = $ _ POST ['name'];
$ Content = $ _ POST ['content'];
$ Blogid = $ _ POST ['blogid'];
$ Datearray = getdate (time ());
$ Date = date ("Y-m-d h: I: s", $ datearray [0]);
If (! Empty ($ name )&&! Empty ($ content )){
// Use the empty function to judge whether the form is not empty.
If (strlen ($ name)> 20 ){
// Judge the length of $ name by null.
Error ("The name exceeds 20 bytes (20 English or 10 Chinese characters)
");
}
F (! Is_numeric ($ _ POST ['blogid']) {
Error ("the hidden data has been illegally modified. please return
");
}
// Because $ blogid is to be put into select, this variable is used to indicate which article the comment belongs to. it is of the int type, although it is a hidden variable, however, attackers can modify the remote submission locally, so we need to check the type before putting it into the select statement.
$ Blogsql = "Select * FROM $ comment_table Where blogid = $ blogid"
$ Blogresult = mysql_db_query ($ dbname, $ blogsql );
$ Blog = mysql_fetch_array ($ blogresult );
If (strlen ($ name) = strlen ($ blog [name]) & strlen ($ content) = strlen ($ blog [content]) {
// Query the length of the two fields in the database. because the name length may be the same, but the two fields are the same, the probability of occurrence is quite small under normal circumstances, so use & to judge at the same time.
Error ("The comments you want to submit already exist. please return
");
}
// Start to judge the interval. For more details, see the content below.
Session_start ();
If (session_is_registered ("time") & time ()-$ _ SESSION ['Time'] <60*2) {error ("sorry, the time interval between your two submissions is less than 2 minutes.
");
} Else {
$ SQL = "Insert INTO $ comment_table (date, name, content, blogid) VALUES ('$ date',' $ name', '$ content',' $ blogid ')"
Mysql_db_query ($ dbname, $ SQL );
Mysql_close ();
$ Time = time ();
Session_register ("time ");
Succeed ("The comment is submitted successfully
");
}}
// End non-empty judgment
Error ("You have not completed all the forms
");
?>
The above is a document that records comment data. The form is as follows:
The code is as follows:
....