1
我想编写一个PHP脚本,即用户可以 打分其他用户的“善”:PostgresSQL:比较前3个IPv4地址号码?
create table pref_rep (
id varchar(32) references pref_users(id) check (id <> author),
author varchar(32) references pref_users(id),
author_ip inet,
good boolean,
last_rated timestamp default current_timestamp
);
要(尽量)防止篡改我想删除 条目在过去一小时内来自相同IP的相同ID
(由于代理/路由器偶尔会出现误报 - 因为作者可以在以后重新提交评级时间;但是在我离开网站的时候,在不同的ID下注册一些白痴并且破坏我的整个数据库并不好):
/* _author_ip will be $_SERVER['REMOTE_ADDR'] */
create or replace function pref_update_rep(_id varchar,
_author varchar, _author_ip inet,
_good boolean) returns void as $BODY$
begin
delete from pref_rep
where id = _id and
author_ip = _author_ip and
age(to_timestamp(last_rated)) < interval '1 hour';
update pref_rep set
author = _author,
author_ip = _author_ip,
good = _good,
last_rated = current_timestamp
where id = _id and author = _author;
if not found then
insert into pref_rep(id, author, author_ip, good)
values (_id, _author, _author_ip, _good);
end if;
end;
$BODY$ language plpgsql;
我有2个问题,请:
1)如果我想比较只是第3号 的IP地址,而不是4,我该怎么办呢? (是的,我知道的A,B,C类IPv4网络的,无所谓这里...)
2)我需要一个索引添加到我的餐桌 或者ID和作者已经索引?
谢谢! 亚历