PHP-based chat room (3)

Source: Internet
Author: User

Now we have the file that needs to be cross-referenced through the $ REMOTE_ADDR variable, so that we can distinguish whether the user who wants to post has been flattened or not. 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 script execution immediately. Before processing the passed variables, insert a check for the flat users so that the flat users cannot use the chat room.
Check the range of the IP address block. A simple function can be easily implemented.
<? Php
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;
}
?>
Then we replace the if in the loop
<? 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 method to get the IP address that is in trouble first. My implementation is to record $ name and $ REMOTE_ADDR to
Iplist.html file. For a separated, secret URL, I can monitor IP addresses while browsing messages. This can add some unexpected benefits, namely the ability to discover counterfeits-the most common "sin" in these places ".
The methods for creating iplist.html and messages.html are basically the same. First, extract the current value from iplist.html. We will strip the U-turn information, the foot tag and the old IP address record, and then create a new record, new header information, and new foot tag. To make the layout clearer, I used a table.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.