i've got this script which i am trying to put on my site, but i do not understand what document root is? sorry to sound such a noob

right index.php, the file i am trying to call pages from a folder called test is using 'test/' the right thing to be doing, it's not to much of a big deal, as i can just add test/ to all the links.

but i was just wondering what the document root was for and have i totally set it up wrong

<?php

# default page
$default = 'test/home.php';

# set document root path
$base = $_SERVER['test/'];

# list of all site pages + the id they will be called by
$pages = array('home' => 'test/home.php','profile' => 'test/profile.php','portfolio' => 'test/portfolio.php','forum' => 'test/forum.php','contact' => 'test/contact.php','calender' => 'test/calender.php');

if(array_key_exists($_GET['page'], $pages))
{
foreach($pages as $pageid => $pagename) {
if($_GET['page'] == $pageid && file_exists($base.$pagename))
{
          /* if somebody's making a request for ?page=xxx and
          the page exists in the $pages array, we display it
          checking first it also exists as a page on the server */
          include $base.$pagename;
      }
   } // end foreach
}
else {
          /* if the page isn't listed in $pages, or there's no ?page=xxx request
          we show the default page, again we'll also just make sure it exists as a file
          on the server */
          if(file_exists($base.$default)) include $base.$default;
}

?> 

    anyone have any idea' what it could be?

      The document root is the server path that is accessible by web visitors and robots. While it can be the server root, it is commonly set as a secondary directory such as test.

      Ok - so you have your server root - which is where the web server will serve web pages from.

      Then you can have document roots - which is the base directory of your application.

      So in your example its document root is invalid and should be: $_SERVER[''DOCUMENT_ROOT'] If you have the page directly off the server root, if its in a directory off the root the just concatenate that on.

      When it looks for pages etc... it can use the $base variable to provide the path to the file to your test directory..

        i am guessing that it sets it to the $base varable then later on adds it to eh rest

        $base.$pagename

        so it can display it

        but if i set $base to test/ it does nothing

        but wouldn't that be the same as just writing it like test/profile.php forexample under page name

        i am so confused.

        if this helps here is a link to the tutorial

        http://www.netcode.net/tutorials/php_mysql/easy_navigation.php

          Sorry - edited my post.

          You need to set $base to $_SERVER['DOCUMENT_ROOT'];

          This is a server variable which stores the server root - i.e. the base directory where the webserver serves pages from.

            it doesn't seem to work if i leave it as document root, btw the 'content' pages, the pages it calls are in a folder called 'test'

              ok,

              No problems - can you at the top of the page do this:

              echo('The Root is here: ');
              print_r($_SERVER['DOCUMENT_ROOT']);
              echo ('<br /> This File path from the root is:');
              print_r($_SERVER['PATH_INFO']);
              die();
              

              Then post the results:

              If there is any directory information in the file path from the root then - you will need to add this to the base.

              i.e. $base = $_SERVER['DOCUMENT_ROOT'].'/test/';

              If not and everything is as should be you will need to add an extra "/" so:
              $base = $_SERVER['DOCUMENT_ROOT'].'/';

              This is because the array that picks the pages up don't include this in the file / directory definition.

                inside my body tags it now looks like this, is this right? have i done it wrong?

                <div align="center">
                	<a name="top"></a>
                <table width="500" border="0" cellspacing="0" cellpadding="0" bgcolor="#666666">
                  <tr> 
                    <td class="top"><img src="../Images/top/logo_new.jpg" width="498" height="70"></td>
                    </tr>
                  </table>
                
                
                 <table width="500" border="0" cellspacing="0" cellpadding="0">
                 	 <tr>
                 <td height="5"></td>
                 </tr>
                 	 <tr>
                 <td class="menu_top">
                 <div id="menu_top">// 
                 <a href="index.php?page=home"> News </a> // <a href="index.php?page=profile">Profile</a> // <a href="index.php?page=portfolio">Portfolio </a> // <a href="index.php?page=forum">Forum</a> // <a href="index.php?page=contact">Contact</a> // <a href="index.php?page=calender">Calender</a>	//	 </div>
                </td>
                	 </tr>
                	 <tr>
                	 <td height="5"></td>
                	 </tr>
                	 </table>
                
                 <table width="500" border="0" cellspacing="0" cellpadding="0">	 
                 <tr>
                <td width="380" valign="top" background="test/profile.php" class="main">
                
                <div id="main">
                
                 <?php
                
                echo('The Root is here: ');
                print_r($_SERVER['DOCUMENT_ROOT']);
                echo ('<br /> This File path from the root is:');
                print_r($_SERVER['PATH_INFO']);
                die();
                
                # default page
                $default = 'test/home.php';
                
                # set document root path
                $base = $_SERVER['DOCUMENT_ROOT'].'/test/';
                
                # list of all site pages + the id they will be called by
                $pages = array('home' => 'home.php','profile' => 'profile.php','portfolio' => 'portfolio.php','forum' => 'forum.php','contact' => 'contact.php','calender' => 'calender.php');
                
                if(array_key_exists($_GET['page'], $pages))
                {
                foreach($pages as $pageid => $pagename) {
                if($_GET['page'] == $pageid && file_exists($base.$pagename))
                {
                          /* if somebody's making a request for ?page=xxx and
                          the page exists in the $pages array, we display it
                          checking first it also exists as a page on the server */
                          include $base.$pagename;
                      }
                   } // end foreach
                }
                else {
                          /* if the page isn't listed in $pages, or there's no ?page=xxx request
                          we show the default page, again we'll also just make sure it exists as a file
                          on the server */
                          if(file_exists($base.$default)) include $base.$default;
                }
                
                ?> 
                <br>
                <br>
                
                <p align="center"><a href="#top">top</a></p>
                	  </div>
                	  </td>
                	  	  <td width="5">&nbsp;</td>
                    <td width="110" valign="top" class="menu">	<div id="menu">
                	<font class="menu_title">Main</font>
                	<br>
                      News<br>
                      Profile<br>
                      Portfolio      <br>      <br>
                	  <font class="menu_title">Interactive</font>
                	  <br>
                	  Forum<br>
                	  Contact<br>
                	  Calender<br>
                	  Partners<br>
                	  </div>
                	  </td>
                	  </tr>
                </table>
                
                <table width="500" cellpadding="0" cellspacing="0">
                	  <tr>
                	  <td height="5"></td>
                	  </tr>
                	  <tr>
                	  <td height="20" class="footer" align="center">copyright 2004 Inverse
                	    Designs</td>
                	  </tr>
                </table>
                </div>

                  well

                  i've done what you said

                  and i've echoed out the base with the added .'test'; on the end and this is what i get
                  /home/www/inversedesigns.superihost.com/test/

                    ok i've got it now, document_root is the root for the sub domain i've got it, sorry for sounding such like a noob, thanks guys...

                      Write a Reply...