Home> php教程> php手册> body text

基于 PHP 的聊天室(三)

WBOY
Release: 2016-06-13 11:21:00
Original
1112 people have browsed it

现在我们有了需要通过$REMOTE_ADDR变量来交叉引用的文件,这样我们可以区分出想要发贴的用户是否已经被扁或没有被扁。很简单:
for ($counter=0;$counter    if ($banned_array[$counter] == $REMOTE_ADDR) {
   print("".
   "You have been banned from this chat
");
   exit;
   }
}
?>
  exit命令将立即停止脚本的执行。在开始对传递过来的变量执行处理之前,插入对被扁用户的检查,这样被扁用户就不能使用聊天室了。
  比较好的解决在某些情况下动态IP地址的问题的一个意见就是,检查IP地址块的所属范围。一个简单的函数可以容易地实现它。
function makeMask($ip) {
   // remember to escape the . so PHP doesn't think it's a concatenation
   $ip_array = explode(".", $ip);
   $ip_mask = "$ip_array[0].$ip_array[1].$ip_array[2]";
   return $ip_mask;
}
?>
  然后我们把循环中的if替换成
for ($counter=0;$counter    if (makeMask($REMOTE_ADDR) == makeMask($banned_array[$counter])) {
   print("".
   "You have been banned from this chat
");
   exit;
   }
}
?>
  我们有了针对动态IP地址的保护措施。
  最后我们需要一种方法最先得到惹麻烦的IP。我的实现是将$name和$REMOTE_ADDR记录到一个名为
iplist.html的文件中。对于一个分离的,秘密的URL,我可以在浏览消息的同时监控IP地址。这可以增加一些意外的好处,就是能够发现假冒者--在这些地方最常犯的“罪”。
  iplist.html与messages.html的创建方法基本上一样。首先将当前的值从iplist.html中取出来,我们剥离掉头信息,脚标和旧的IP记录,然后创建一个新的记录,新的头信息,新的脚标。为了让布局更清楚,我使用了表格。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!