PHP Application--A complete handbook of Chat Room Development (iii) _php tutorial

Source: Internet
Author: User
Tags regex expression
Now we have a file that needs to be cross-referenced by the $REMOTE_ADDR variable, so we can distinguish whether the user who wants to post has been flattened or not flattened. Very simple:
  
     
for ($counter =0; $counter if ($banned _array[$counter] = = $REMOTE _addr) {
Print ("".
"You had been banned from this chat");
Exit
}
}
  
?>
  
The exit command stops the execution of the script immediately. Before starting to perform processing on the passed variable, insert a check on the flattened user so that the flat user cannot use the chat room.
  
A better solution to the problem of dynamic IP addresses in some cases is to check the scope of the IP address block. A simple function makes it easy to implement.
  
     
function Makemask ($IP) {
Remember to escape the. So PHP (as the current 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 with the
  
     
for ($counter =0; $counter if (Makemask ($REMOTE _addr) = = Makemask ($banned _array[$counter])) {
Print ("".
"You had been banned from this chat");
Exit
}
}
  
?>
  
We have protection against dynamic IP addresses.
  
  
Finally we need a way to get the IP that gets in trouble first. My implementation is to record $name and $remote_addr to a named
Iplist.html in the file. For a separate, secret URL, I can monitor the IP address while browsing the message. This can add to some of the unexpected benefits of being able to spot counterfeiters-the most common "sin" 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 off the turn information, the foot tag and the old IP record, and then create a new record, new header information, new foot tag. To make the layout clearer, I used the table.
  
     
$header = "
"; $footer = "
";
$new _ip = "$name$REMOTE _addr";
  
$ip _array = File ("iplist.html");
for ($counter = 1; $counter < $counter + +)
$old _ips.= $ip _array[$counter];
  
?>
  
Simply write the content to disk as you did with the message file, so we have a web chat room. It's better than Java to cross-platform compatibility, and nothing more than 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 can automatically add trouble to the flattened list, and writing a regex expression that scans the message body for URLs and e-mails, and automatically convert it into links (as Outlook Express and ICQ do).
  
Give it a try, have fun and get some experience. That's how I started in PHP (as a mainstream development language now) and now I'm working on it.
I wish you a happy chat!
  

http://www.bkjia.com/PHPjc/508608.html www.bkjia.com true http://www.bkjia.com/PHPjc/508608.html techarticle now we have a file that needs to be cross-referenced by the REMOTE_ADDR variable, so we can distinguish whether the user who wants to post has been flattened or not flattened. Very simple: PHP (as ...

  • Related Article

    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.