Jump to content

"Nested" include() using site root addressing


dawirick

Recommended Posts

IIS  :'(

php 4.4.2  :-[

(it's what i'm stuck with)

 

I am working on a three column site (internal corprate site)

 

Header

Menu

LeftCol = SubMenu

CenterCol = Content

RightCol = RotatingContent

Footer

 

I use the Menu to include() subMenu and Content (no problem). 

 

I have a define('SITE_PATH', 'www.my/site/root/);

 

$server = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$base = "/bmet";
define('SITE_PATH',substr("$server",0,strpos($server,$base)+strlen($base))

 

I can echo(SITE_PATH); no problem.

 

My problem is trying to update the Content portion from the SubMenu using include(SITE_PATH.'path/to/include);

It doesn't include...I get the lovely "Warning...failed to open stream: No such file or directory...

 

If I enter the path directly into the address bar, *BOOM* the page appears.  So I know the path is correct.

 

Why isn't it working?  :confused:

 

I'm addressing directly from the site root, not relative.

 

EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE

 

Menu selection = Forms

 

subMenu loads just fine:

<?php
/*
* #leftCol FORMS ($menu)
*/
?>
<h1 class="boxit center">FORMS MENU</h1>
<p class="center"><a href="?page=forms&menu=forms&list=pat">STATUS</a></p>
<p class="center"><a href="?page=forms&menu=forms&list=gen">GENERAL USE</a></p>
<p class="center"><a href="?page=forms&menu=forms&list=info">INFORMATIONAL</a></p>

 

Content loads fine:

<?php
/*
*  #centerCol FORMS
*/
$pageTitle = "Forms";
?>
<div class="center"><h2>FORMS</h2></div>
<div class="center"><h3><a href="docs/pdf/scheduling/holiday2010.pdf" target="_blank">2010 HOLIDAY SCHEDULE</a></h3></div>
  <?php
  	if (isset($_GET['list']))
	$list = $_GET['list'];
	else
	$list = "home";
  ?>

until

 

<div id="forms" class="center"><? include(SITE_PATH."lib/loads/pages/forms/".$list.".php");?></div>

 

then **ERROR**

Link to comment
Share on other sites

<? include(SITE_PATH."lib/loads/pages/forms/".$list.".php");

 

If SITE_PATH is a variable, where's the $?

 

It's not a variable.

 

define('SITE_PATH',substr("$server",0,strpos($server,$base)+strlen($base))

 

dawirick: how does the SITE_PATH look like?

Link to comment
Share on other sites

SITE_PATH = www.site/root/bmet/testing/update/

(intranet site)

 

echo (SITE_PATH); = correct complete URI for site root

 

Like I said eralier, I can copy the URI directly out of the error and paste it into the address bar and the referenced page loads just fine.

 

All three columns of base page load the same, dependant on the variable ($page (centerCol), $menu (leftCol), or $ad (rightCol))...

			if(isset($_GET['menu'])){
				$menu = $_GET['menu'];
			}else{
				$menu = 'home';
			}
			if($leftCol != $menu){
				include(MENU_LOAD.$menu.'.php');
				$leftCol = $menu;
                                }

Primary menu link calls "index.php?page=library&menu=library&ad=fda" or whatever depending on what is to be included in the various portions of the page.

 

The various XXXX_LOAD refernces (i.e. PAGE_LOAD, MENU_LOAD, ADS_LOAD) are defined as relative references ... define('PAGE_LOAD', 'lib/loads/pages/'), etc... and work just fine.  The problem is when I try to include() another *.php file using a literal reference ... include(SITE_PATH.yada/yada/yada)

 

The if($XXX != YYY) statement stops that portion of the page from being reloaded if nothing has changed.

 

A picture is worth a thousand words (see attachments)...

 

openingScreen loads perfectly...

FormsPage, main area loads fine except for the include() area.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Just for curiosity sake have you tried hard coding a static include? I assume that this then should work since copying the uri works directly in the address page. Or try a urlencode on it just for the hell of it, doubt that'll work unless you've some characters in there it's trying to parse but wth try anything right.

 

<div id="forms" class="center"><? include("../whatever/lib/loads/pages/forms/B_list.php");?></div>

Link to comment
Share on other sites

Hardcoding the URI does not make a difference.

 

However, if I place the directory of the load files within the primary directory and use a relative reference...no problem.

(i.e. include('forms/'.$list.'.php'); as opposed to include(SITE_PATH.'/lib/loads/pages/forms/'.$list.'.php'); )

 

This doesn't answer my question though...shouldn't I be able to load a literal reference?

Link to comment
Share on other sites

Yeah you should that's why I asked to be sure it wasn't a bug elsewhere causing the issue... Maybe the constant in this case is having issues...

 

Hmm try dropping the constant into a variable and within the include use that variable. (again I doubt this should make a difference... but then again I've seen stranger things with php running on a windows server too.

 

$temp_const = constant("SITE_PATH"); 
include($temp_const.'/lib/loads/pages/forms/'.$list.'.php');

Link to comment
Share on other sites

Tried your suggestion...no difference.

 

I get so tired of trying to appease MS products...

 

Ha isn't that the truth... try working with sharepoint & thirdparty software sometime because someone thought it was a good idea instead of using a program language to build it. Maddening...

 

At any rate... sorry I couldn't be more helpful. Hmmm, but maybe bumping this, this many times someone else will suggest something that's more advanced then I am hopefully.

Link to comment
Share on other sites

is www.site the name of the directory?  It's looking for the file "./www.site/root/bmet/testing/update/...", not pulling the URL "http://www.site/root/bmet/testing/update/"

Your site path should be an actual path leading on your server, not a URL.

 

Just define the path yourself

 

define(SITE_PATH,'/home/user/www/');

  :o  OY VAY!

.

Okay!  I think that answers my question

 

Yes, I am trying to reference a URL.

 

My problem with referencing the "root directory" is I am operating out of a mapped directory (not in the actual www directory, not even on the same server).

 

Guess I'm stuck with relative references ONLY (unless someone has a creative suggestion).

 

Thanks to all for your help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.