<?
// php教程限制用户60秒后发布评论实例代码
/*
create table `test`.`abc` (
`id` int( 4 ) not null auto_increment ,
`times` int( 4 ) not null default '0',
`ip` varchar( 200 ) null default null ,
primary key ( `id` )
) engine = myisam
*/
if( $_post )
{
$conn = mysql教程_connect('localhost','root','root') or die('mysql server 2001');
mysql_select_db('test',$conn);
$date = time();
$ip = $_server['remote_addr'];//获取ip地址,这是测试所以没作判断了
$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('坐下来休息一下吧,您的动作太快了,请60秒后再发布你的信息!');
}
else
{
$sql = "insert into abc(times,ip) values('$date','$ip')";
$insert = mysql_db_query('test',$sql,$conn);
if( $insert )
{
echo '评论成功';
}
else
{
echo '评论失败';
}
}
}
?><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="发表评论">
</form>
本站原创文章转载注明来源于www.111cn.net否则必究