Building the View Details Page in a PEAR CMS - Code Explained
(Page 2 of 4 )
The first part of this script tries to determine if the currently logged-on user actually has the right to be viewing this script. It does this by starting a session, which will have two session variables available. The code will use one of these variables to check if a user should view the page.
This is how it does this: first, it calls the session_start() function to open up a session. This is because this piece of code uses the application-wide session variable called ‘author_name’ to determine if it should redirect the user to the login page or not. It tests the variable by checking to see if it is set using the appropriately named isset() function of PHP, which evaluates the parameter that it is passed to see if it contains any values.
If it does contain a value, then the user will be allowed to use the page. If it does not contain any values, then the user is redirected to the login page, because the program logically assumes that the user is not authenticated:
<?php
session_start();
if(!isset($_SESSION['author_name'])){
//redirect to login page
header("location:login.php");
}
?>
The next part of the page starts to build the HTML portion of the script. The HTML code will also include a table that will eventually host the dynamic content that we want to display:
<!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" -->
Next: Table with Navigation Panel >>
More PEAR Articles Articles
More By David Web