Tutorials | Application examples based on PHP chat room (iii)
Now we have files that need to be cross-referenced through the $REMOTE_ADDR variable, so that we can tell if the user who wants to post has been flattened or not flattened. Very simple:
<?php
For ($counter =0 $counter <sizeof ($banned _array); $counter + +) {
if ($banned _array[$counter] = = $REMOTE _addr) {
Print ("<font color=" red "face=" Arial "align=" Center ">".
"You have been banned from this chat</font>");
Exit
}
}
?>
The exit command stops the execution of the script immediately. Insert a check of the flattened user before starting to perform processing on the passed variables so that the flat user cannot use the chat room.
A better solution to the problem of dynamic IP address in some cases is to check the scope of the IP address block. A simple function can easily implement it.
<?php
function Makemask ($IP) {
Remember to escape the. So PHP doesn ' t do it ' s a concatenation
$ip _array = Explode (".", $ip);
$ip _mask = "$ip _array[0]. $ip _array[1]. $ip _array[2]";
return $IP _mask;
}
?>
Then we replace the IF in the loop with the
<?php
For ($counter =0 $counter <sizeof ($banned _array); $counter + +) {
if (Makemask ($REMOTE _addr) = = Makemask ($banned _array[$counter)) {
Print ("<font color=" red "face=" Arial "align=" Center ">".
"You have been banned from this chat</font>");
Exit
}
}
?>
We have protective measures for dynamic IP addresses.
Finally we need a way to get the first annoying IP. My implementation is to log $name and $remote_addr to a
Iplist.html in the file. For a separate, secret URL, I can monitor the IP address while browsing the message. This can add some windfall benefits, that is, the ability to detect counterfeiters-the most common crime in these places.
Iplist.html and messages.html are basically the same way of creating. First take the current value out of the iplist.html, we peel back the turn information, pin and old IP records, and then create a new record, new header information, and a new PIN. To make the layout clearer, I used the table.
Simply writing the content to disk is the same as the message file, so we have a web chat room. Better cross-platform compatibility than Java, and no need for anything but a Web browser--I've heard that even Dreamcast works like this!
There are some things you might want to try to do yourself, including merging some common code snippets into functions, writing a script that automatically increases the number of troublesome people to a flattened list, and writes a regex expression that scans the message body for URLs and e-mails. and automatically convert them to links (as Outlook Express and ICQ do).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.