Php
RWB
Icrontian
I am working on a CMS, I bought a book on XML but it uses alot of PHP, I thought the book would explain in more detail the PHP it uses but it doesn't.... not very well at least.
So I have a bunch of php pages for a CMS built 90% on PHP and I kinda get the jist of it, but how is it that a variable declared in one page work on another that is not declared but is using this variable??
So I have a bunch of php pages for a CMS built 90% on PHP and I kinda get the jist of it, but how is it that a variable declared in one page work on another that is not declared but is using this variable??
0
Comments
It is likely that a session variable is being used - this means it can be declared on one page and referenced on any other page.
Are you able to post a code snippet which shows how the variable is declared on the first page, and how this variable is being used on another page?
Regards,
Scott
common.inc.php
[PHP]<?php
session_start();
$fileDir = $_SERVER . '/xml/';
?>[/PHP]
index.php
[PHP]<?php
include_once 'common.inc.php';
$file = $fileDir . 'homepage.xml';
$homePage = simplexml_load_file($file);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo htmlentities($homePage->headline); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="xmlcms.css" type="text/css" />
</head>
<body>
<?php
include 'navtop.inc.php';
?>
<div id="navSide">
<?php
include 'search.inc.php';
include 'news.inc.php';
?>
</div>
<div id="mainContent">
<?php
echo '<h1>' . htmlentities($homePage->headline) . '</h1>';
echo '<p><small>' . htmlentities($homePage->description) . '</small></p>';
echo $homePage->body;
?>
</div>
</body>
</html>[/PHP]
doSearch.php
[PHP]<?php
include_once 'common.inc.php';
$term = $_POST[term];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html1/DTD/xhtml1-transitionl.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include 'navtop.inc.php';
?>
<div id="navSide">
<?php
include 'search.inc.php';
include 'news.inc.php';
?>
</div>
<div id="mainContent">
<?php
$handle = opendir($fileDir);
$items = array();
while (($file - readdir($handle)) !== FALSE) {
if (is_dir($fileDir . $file)) continue;
if (!eregi("^(news|artcle|webcopy).*\.xml$", $file)) continue;
$xmlItem = simplexml_load_file($fileDir . $file):
if ((stripos($xmlItem->keywords, $term) !== FALSE or
stripos($xmlItem->headline, $term) !== FALSE or
stripos($xmlItem->description, $term) !== FALSE and
(string)$xmlItem->status == 'live') {
$item = array();
$item = (string)$xmlItem;
$item = (string)$xmlItem->headline;
$items[] = $item;
}
}
?>
</div>
</body>
</html>
[/PHP]
OK I think I get it now that I am posting this code... the include command is bringing the common.inc.php file into play for each page which is in turn giving it the variable $fileDir?
[PHP]<?php
// Start contents of 'common.inc.php';
session_start();
$fileDir = $_SERVER . '/xml/';
// End contents of 'common.inc.php';
$file = $fileDir . 'homepage.xml';
$homePage = simplexml_load_file($file);
?>
?> [/PHP]
So $fileDir is a local variable for the page.
Regards,
Scott
If you only have two weeks to go I think you need to make a decision now whether you should look for an existing CMS.. or it's going to be a very long and painful next few weeks!
Regards,
Scott
Of course it depends on what features the first release requires - but even something straightforward can result in a fair amount of effort particularly with the administration section (i.e. manage user accounts, manage/publish content, set-up configurable sections/menus for the site, etc).
Assuming the requirements are not bedded down you are going to spend at least several days meeting with users/preparing prototype screenshots/developing a design as well - reducing the programming time available in the two weeks..
If you are going to build this yourself I would suggest forgetting about the backend admin section, aim to get a database driven CMS up and running and just insert articles/config straight into the database. After that, work on the admin section.
Scott