PHP
  Home arrow PHP arrow Page 4 - Creating an Administration Area for a Simple Threaded Discussion Forum
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Creating an Administration Area for a Simple Threaded Discussion Forum
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2006-10-23


    Table of Contents:
  • Creating an Administration Area for a Simple Threaded Discussion Forum
  • Code
  • The delall() and deltopic($uid) functions
  • Database connection, bad words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Creating an Administration Area for a Simple Threaded Discussion Forum - Database connection, bad words
    ( Page 4 of 4 )

    The function below sets the database connection details:

    function forumdb(){
    $dbname="forum";
    $host="localhost";
    $dbh=mysql_connect($host) or die ('I cannot connect to the
    database because: ' . mysql_error());
    mysql_select_db ($dbname) or die('I cannot select the database
    because: ' . mysql_error());
    }

    Remember to add your connection details to the this function.

    This function shows a form that will enable you to enter a word that you want banned from the forum.

    function showfrm(){
    echo '<center> <form name="form1" method="post" action="' .$_SERVER['PHP_SELF'].'?action=writewords"> ';
    echo 'Enter word to ban:<br>
        <input type="text" name="word"><br>
        <input type="Submit" name="Submit" value="Submit"
    class="altButtonFormat"> ';
     echo '</center></form>';
     echo '<center><font color="#FF0000">Banned words will be replace
    with XXXX.</font></center>';
    }

    Here's what the form looks like:

     

    Fig. 3 The form is presented when you want a new word to be added to the banned word list.

    The "getword()" function retrieves all the banned words:

    function getword(){
    echo "<center><b><h3>Banned Words</h3></b></center>";
    echo "<center>---------------------</center>";
     $words=file('badwords.txt');
    for($i=0; $i < count($words); $i++){
    echo "<center>$words[$i]</center><br>";
    }
    }

    The function interacts with a text file on the disk and uses PHP's very handy file handling functions to retrieve a list of banned words. Here's a screen shot of the above function result:

    Fig. 4 A list of  banned words.

    The writeword() function writes all the words to a file called "badwords.txt."

    function writeword(){
    if(isset($_POST['Submit'])){
    $word=$_POST['word'];
    if($fp=fopen('badwords.txt', 'a+')){
    fwrite($fp, "$wordrn");
    fclose($fp);
    echo "<center>The word <b>$word</b> has now been
    banned.</center>";
    }else{
    echo "could not open file";
    }
    }
    }

    As I mentioned before we will use a $action variable to receive the value passed from the link that has been clicked, and then use the switch command to handle the value accordingly. Here's a snippet of the switch command:

    if(isset($_GET['action'])){
    $action=$_GET['action'];
    switch($action)
    {
        Case "gettopics";
            getall();
        break;
      Case "deleteall";
            delall();
            break;

    As the code above shows, once the user clicks on the "get all main topics" link the "getall();" function is called. The same thing happens when the user clicks on the "Delete all topics" link; the "delall()" function is called.

    Conclusion

    That's it for the admin section of the forum. Here are a few suggestions to improve its performance: create a table to store the "bad words." This will enable you to add/remove words more easily than you would with a file-based system. Try to set up a login script to control access to the admin area, as I'm sure you would not want just anyone to have access to the functions on that page!



     
     
    >>> More PHP Articles          >>> More By Jacques Noah
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek