PHP restricts user to post comment instance code after 60 seconds

Source: Internet
Author: User
Tags get ip mysql tutorial php tutorial

;?
//php tutorial limits user 60 seconds post Comment Instance code
/*
CREATE TABLE ' test '. ' abc ' (
' id ' int (4) NOT NULL auto_increment,
' time S ' int (4) NOT null default ' 0 ',
' IP ' varchar null default NULL,
Primary key (' ID ')
) engine = Myi Sam
*/
if ($_post)
{
  $conn = mysql tutorial _connect (' localhost ', ' root ', ' root ') or Die (' MySQL server 2001 ' );
 mysql_select_db (' Test ', $conn);
  $date = time ();  
  $ip = $_server[' remote_addr '];//get IP address, this is a test so it's not judged.
  $wait = "Select TIMES,IP from ABC where ip= ' $ip ' and ($date-times<60) Order BY id DESC limit 1 ";


$rows = mysql_query ($wait) or Die (Mysql_error ());
if (mysql_num_rows ($rows))
{
Die (' Sit down and have a rest, you move too fast, please release your message in 60 seconds! ');
}
Else
{

$sql = "INSERT INTO ABC (TIMES,IP) VALUES (' $date ', ' $ip ')";
$insert = mysql_db_query (' Test ', $sql, $conn);
if ($insert)
{
Echo ' comment success ';
}
Else
{
Echo ' comment failed ';
}

}
}
?>

<form name= "Form1" method= "Post" action= "" >
<label for= "TextField" ></label>
<input type= "text" name= "www111cnnet" id= "TextField" >
<input type= "Submit" name= "button" id= "button" value= "comment" >
</form>


Original articles reproduced in this site is indicated from www.111cn.net otherwise must investigate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.