PHP application-full chat room Development Manual (3) _ PHP Tutorial

Source: Internet
Author: User
Tags regex expression
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 ="
";$ Footer ="
";
$ 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 (...

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.