Php

RWBRWB Icrontian
edited October 2006 in Internet & Media
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??

Comments

  • edited October 2006
    Hi RWB,
    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
  • RWBRWB Icrontian
    edited October 2006
    Since I am working out of a book I don't know yet if this is the complete code... I'll use $fileDir as a example...

    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"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <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"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <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?
  • edited October 2006
    That's spot on RWB! When the page is accessed common.inc.php is included into the top of each page. Below is what the index page would look like at runtime (except for the start and end comments of course)-

    [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
  • RWBRWB Icrontian
    edited October 2006
    Thanks for confirming this! I hate to say it though, this was for a project at work and right now I am thinking I can't meet the deadline which is like 2 weeks from now. I really wanted to use my own CMS instead of some generic one of the web. :( PHP is too steep of a learning curve...
  • edited October 2006
    Unfortunately writing any sort of significant software product takes time, more so if you are starting out.

    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
  • LincLinc Owner Detroit Icrontian
    edited October 2006
    Wow dude, yeah, you can't possibly go from zero to CMS-building in PHP in two weeks... if you can, we have a job for you! :p
  • RWBRWB Icrontian
    edited October 2006
    I am not going from zero, I've been working with php for years now, but it's been on and off and not for very long each time so I efectivly forget the stuff I knew from before.
  • edited October 2006
    Hi RWB, even with your experience it's going to be very difficult (nay impossible?!) to develop a solid CMS system within 2 weeks. Even working days and nights! :)

    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
  • RWBRWB Icrontian
    edited October 2006
    As a backup I've been working on an installation on Joomla, I kinda figured this may occur so I didn't wanna take too much of a chance. I didn't wanna use Joomla becuase it's the best I could find and yet it doesn't DISPLAY the information the way I kinda need it. But it'll be a good substitute until I build my own CMS. Also I didn't want Joomla becuase I can't find jack for documentation on transferring what I build on one system to the live server. Plus I have MySQL and the live server uses MSSQL.
Sign In or Register to comment.