PHP application-full chat room Development Manual (3 ). 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 (now we have a 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:
For ($ counter = 0; $ counter If ($ banned_array [$ counter] = $ REMOTE_ADDR ){
Print ("".
"You have been banned from this chat ");
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.
Function makeMask ($ ip ){
// Remember to escape the. so php (as the mainstream development language) doesnt think its 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
For ($ counter = 0; $ counter If (makeMask ($ REMOTE_ADDR) = makeMask ($ banned_array [$ counter]) {
Print ("".
"You have been banned from this chat ");
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.
$ Header ="
";
$ New_ip ="$ Name$ REMOTE_ADDR";
$ Ip_array = file ("iplist.html ");
For ($ counter = 1; $ counter <20; $ counter ++)
$ Old_ips. = $ ip_array [$ counter];
?>
Simply writing the content to the disk is the same as writing the content to the message file, so we have a web chat room. It has better platform-crossing compatibility than Java, and does not need anything except a web browser-I heard that Dreamcast works like this!
There are some things you may want to do by yourself, including merging some common code snippets as functions, writing a script that can automatically increase the trouble into the flattened list, and writing a regex expression, you can scan the URL and e-mail in the message body and convert it to a link (as in Outlook Express and ICQ ).
Try it and have some experience. This is how I started with php (as the mainstream development language) and now I have taken it as a profession.
Happy Chat!
Bytes. Simple :? Php (...