PEAR Articles
  Home arrow PEAR Articles arrow Page 4 - Building the View Details Page in a PE...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
PEAR ARTICLES

Building the View Details Page in a PEAR CMS
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-11-05

    Table of Contents:
  • Building the View Details Page in a PEAR CMS
  • Code Explained
  • Table with Navigation Panel
  • Displaying the Article

  • 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


    Building the View Details Page in a PEAR CMS - Displaying the Article


    (Page 4 of 4 )

    Because the purpose of this script is to display the full body of the article, which includes the title date of submission and other actual text, the script requires a story ID to actually extract the article from the database. Two query string numbers are sent to it. The two numbers are IDs of the author and the article, respectively. This means that the script has to judge which of the two it has received and then construct an appropriate SQL query.

    But first we have to filter the data that we receive across the Internet. We need to filter the data because malicious users can easily tamper with the query string number that is sent to the application by, for example, changing the number into a string. To get more specific, if you’ve clicked on the first story that is listed on the main page of the application, it will send a query string that looks like this over the browser:


    http://localhost/pear/view.php?sid=1


    A malicious user can change that number into a letter, like so:


    http://localhost/pear/view.php?sid=y


    which will produce unpredictable results that can expose security vulnerabilities. So we have to take basic steps to prevent this from happening. The code below uses the is_numeric() function to see if the query string passed a number or a letter. It will evaluate to false if the parameter that is passed is not a number. First the code checks to see if an author id has been sent:

    if(isset($_GET['aid'])){

    If so, it checks to see if the id is a number using the is_numeric() function:

    if(is_numeric($_GET['aid'])){

    If the id is a number then we filter it further by using the mysql_real_escape_string() function which “cleans” the variable and readies it for use in a query:

    $aid=mysql_real_escape_string($_GET['aid']);

    $sql = "SELECT * FROM stories WHERE aid='".$aid."'";

    }else{

    If the ID is not a number, then an error message is displayed:

    echo "Error invalid format";

    }

    }

    The second part of the code does exactly the same thing that the code above does. The only difference is that the ID that it works with is not an author ID but a story id, or sid:

    if(isset($_GET['sid'])){

    if(is_numeric($_GET['sid'])){

    $sid=mysql_real_escape_string($_GET['sid']);

    $sql = "SELECT * FROM stories WHERE sid='".$sid."'";

    }else{

    echo "Invalid Format";

    }

    }

    Since the SQL queries are defined in the code blocks above, the code continues to run, using the $db->query function to execute the query:

    $res = $db->query($sql);


    We test the results by checking to see if the $res variable contains any records, if it does we run a while loop to retrieve them. It should actually only contain one record since the whole point of the script is to show only one article in full:


    if($res){

    while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {

    ?>


    The code then continues to build the static table that will host the article that the user wants to read. The table will be filled with dynamic data that is retrieved from the database. The table will show the title, date of publication and the story itself:


    <tr class="title">

    <td colspan="2" class="title"><?php print $row->title ?></a></td>

    </tr>

    <tr>

    <td width="18%">&nbsp;</td>

    <td width="82%" class="auth"> published on: <?php print $row->s_date ?></td>

    </tr>

    <tr>

    <td colspan="2" class="maintxt"><p><?php print $row->story ?></p></td>

    </tr>

    If the $res variable does not contain any records, the code displays a message stating exactly that:


    }else{

    ?>

     

    <tr>

    <td colspan="2" class="maintxt"><p>No article found</p></td>

    </tr>

    <?php } ?>


    The HTML table is then closed and the HTML for the page is also closed.

    </table>

    <!-- InstanceEndEditable --></td>

    </tr>

     

    <tr class="copy">

    <td colspan="2">&copy;2008</td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT