for ($counter=0;$counter
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
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记录,然后创建一个新的记录,新的头信息,新的脚标。为了让布局更清楚,我使用了表格。
$header = "
$new_ip = "
$ip_array = file("iplist.html");
for ($counter = 1; $counter $old_ips.= $ip_array[$counter];
?>
简单地把内容写入磁盘与对message文件所做的一样,这样我们就有了一个web聊天室。比Java有更好的跨越平台的兼容性,并且除了一个web浏览器什么都不需要了--我听说甚至Dreamcast就是这样工作的!
有一些东西你可能想试着自已做一下,包括合并一些常用代码片段为函数,编写一个可以自动增加惹麻烦的人到被扁列表中的脚本和编写一个regex表达式,可以扫描消息正文中的URL和e-mail,并将之自动转换成链接(象Outlook Express 和ICQ做的那样)。
试一试,体会一下乐趣,得到一些经验。这就是在PHP方面我是如何开始的并且现在我已经以它为职业了。
祝聊天快乐!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
