PHP
  Home arrow PHP arrow Page 2 - Chatter
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Chatter
By: Roger Stringer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2004-11-08

    Table of Contents:
  • Chatter
  • Configuration
  • View Chatter
  • Manage the Chatter
  • Secure it

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Chatter - Configuration


    (Page 2 of 5 )

    We'll create a file called 'chatter.php', this file is going to be used to store the database connection info.

    <?php
    $con = mysql_connect("localhost","user","pass");
    $db = mysql_select_db("database");
    ?>

    Post Chatter

    Cut and paste the following code into a blank file and named it 'post.php' (without quotes).

    <?php
    include('chatter.php');
    if ($name == '' || $msg == '' || $name == 'name' || $msg == 'message') {
    die ("Error! You cannot fill in an empty shout. Please try again.");
    }
    $blockedip = "select * from blocked_ips WHERE ip='".$REMOTE_ADDR."'";
    $ipcheck = mysql_query($blockedip);
    while ($row = mysql_fetch_array($ipcheck)){
    if( $row["ip"] == $REMOTE_ADDR){
    die ("IP banned, you cannot post.");
    }
    }
    $blockedname = "select * from blocked_nicks WHERE name='".$name."'";
    $namecheck = mysql_query($blockedname);
    while ($row = mysql_fetch_array($namecheck)){
    if( $row["name"] == $name){
    die ("Username has been banned. You may not post.");
    }
    }
    $last_entry = "select * from chatterblock order by id desc limit 1";
    $check = mysql_query($last_entry);
    while ($row = mysql_fetch_array($check)){
    $lastname = $row["name"];
    $lastmsg = $row["msg"];
    }
    if ($lastname == $name && $lastmsg == $msg){
    die ("Error! Duplicate entry detected, please submit only once.");
    }
    $name = htmlspecialchars($name);
    $msg = htmlspecialchars($msg);
    $q = "insert into chatterblock (id,name,msg,url,entered,ip) VALUES ('','$name','$msg','$url',now(),'$REMOTE_ADDR') ";
    $result = mysql_query($q);
    if ($result) {
    header('Location: view.php');
    }
    ?>

    Basically, the above code runs a check to make sure the user doesn't submit a blank entry. Notice that in our chatter.html, we stated the default value for name to be 'name' and msg to be 'message', therefore the basic check should also include the default values. Otherwise, the user can just click 'submit' endless times, and you get the same meaningless entry over again.

    Next, the script will strip off all the HTML tags that may be inserted into the chatterblock. This ensures that no one enters codes that may cause the chatterblock to look weird, among other things. Then it'll insert the entry into the database to be stored and, if successful, redirect the user to view the chatterblock.

    More PHP Articles
    More By Roger Stringer


       · Once again, after criticising the "Building a Quick and Easy Tag Board" article, I...
       · I was to trying the scripts but when others user posting into it ..iframe shout box...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT