Creating the Main Pages of a PEAR CMS - Code Explained
(Page 2 of 4 )
The first part of the script has PHP code that deals with determining if a user has the right to view it. The code itself is very simple; first, it calls the ob_start() function, which will prevent the "headers already sent" error message. Then it calls the session_start() function to open up a session. It does this because this piece of code uses the application-wide session variable called "author_name" to determine whether or not it should redirect the user to the login page. This will happen if the user is not authenticated.
<?php
ob_start();
session_start();
if(!isset($_SESSION['author_name'])){
//redirect to login page
header("location:login.php");
}
?>
The next part of the code simply builds the HTML for the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="Templates/pear.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" class="bord">
<tr class="header1">
<td colspan="2"><div align="center">Content Management System </div></td>
</tr>
<tr>
<td width="5%" valign="top"><!-- InstanceBeginEditable name="EditRegion4" -->
Then the table that will host both the listing of the articles and the navigation panel is built:
<table width="100%" border="0" cellspacing="0" class="navbord">
<tr>
<td colspan="2" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#0066FF" class="section"><strong>Section</strong></td>
</tr>
<tr class="navbord">
<td class="nav"><a href="logout.php">Logout</a> </td>
<td><img src="images/user.gif" width="16" height="16" alt="" /></td>
</tr>
<tr class="navbord">
<td colspan="2" class="nav"><a href="main.php">Home</a></td>
</tr>
<tr class="navbord">
<td colspan="2" class="nav"><a href="authors.php">Authors</a></td>
</tr>
Next: More Code >>
More PEAR Articles Articles
More By David Web