<?
// php教程限制使用者60秒後發佈評論實例代碼
/*
create table `test`.`abc` (
`id` int( 4 ) not null auto_increment ,
`time s` int( 4 ) not null default '0',
`ip` Varchar( 200 ) null default null ,
primary key ( `id` )
) engine = myi sam
*/
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' a nd ($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="jzread" id="textfield">
<input type="submit" name="button" id="button" value="發表評論">
</form>