Jump to content


grrr what am I doing wrong?


6 replies to this topic

#1 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 04 May 2006 - 11:05 AM

this is a weird problem I am having. I have a document called varList.php that has the root direcotry of the site. code:

<?php
	 define("ROOT_LOC", $_SERVER["DOCUMENT_ROOT"]);
?>

on index.php I have something like this (ill use site for example):
require_once('www.site.com/varList.php');
include ($ROOT_LOC."overallHeader.php"); ?>

for some reason, if the overallHeader is in a different folder, it wont work. Say that the overallHeader is in the main directory, if I make a page and put it in www.site.com/test/index.php, it would say this:

Quote

Warning: main(overallHeader.php): failed to open stream: No such file or directory in /usr/home/site/www/test/index.php on line 19

it looks like the varList isnt working and if I try to include a fil in the root directory, it will try to include it in the test directory instead. How can I get the variable to work? When I echoed it, I got nothing. am I defining it wrong?

Edited by TheUnforgiven512, 04 May 2006 - 11:09 AM.


#2 DanWilliamson

    P2L Jedi

  • Members
  • PipPipPip
  • 650 posts

Posted 04 May 2006 - 11:25 AM

I won't pretent to know what you are talking about but wouldn't you use:

require_once('varList.php');
include ($ROOT_LOC."overallHeader.php"); ?>


#3 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 04 May 2006 - 11:28 AM

well no I dont want to put the varList in every folder of my page. basically what I want to do is get it to include the overallHeader from the root directory, and if that directory changes, I wont have to edit hundreds of files

#4 DanWilliamson

    P2L Jedi

  • Members
  • PipPipPip
  • 650 posts

Posted 04 May 2006 - 11:29 AM

Ahh I get you know, like I said I don't fully know what you meant =]

#5 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 04 May 2006 - 12:15 PM

err I have tried everything I can think of. I even made it just a variable and that didnt work. any ideas why its not working?

#6 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 04 May 2006 - 01:12 PM

Well, something I might have read somewhere, "$ROOT_LOC" shouldn't have the $, because it isn't a regular variable or something. Try it without the dollar, like

require_once('varList.php');
include (ROOT_LOC."overallHeader.php"); ?>

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 04 May 2006 - 03:20 PM

The easiest fix i can think of for this would be to simply not worry about requiring anything.
include ($_SERVER['DOCUMENT_ROOT'].'/overallHeader.php');
Also note, ROOT_LOC would be a constant, and that is why it wouldn't have the $ in front of it.

And, if that doesn't work, or you have other reasons for requiring the varList, you would need to add the http:// before it, or simply not worry about your domain at all.
Why not worry you say? Don't want to copy the file a thousand times you say? Don't worry, you don't have to. That's what relative paths are for. I don't even think you'd need them anyway. Any included file retains the CWD of the file that included it.
If you the included file is in a different directory, just back up to it.
include '../varList.php';

Edited by rc69, 04 May 2006 - 03:22 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users