PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 25th, 2003, 08:33 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
PHP's include/require

I love this tag... I'm using it the same way most people are using it, for headers & footers...

how do you require something in a folder outside of the one that the script is in? ideally, i'd like a generic tag that will call a certain header in one folder...

i realize its probably not very clear... so here's an example...

lets say i have header.php in the folder /config/ (sub-folder from within the webspace root folder)

i've tried require('/config/header.php'); but that doesn't seem to work... I realize require('config/header.php'); would work for that file in the same directory, but what about files in various directories?

Alternatively, i can't help but notice this part in the error line: (include_path='.;c:\php4\pear')

A supplement question could be, how do i modify the include_path?

Reply With Quote
  #2  
Old January 25th, 2003, 08:40 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
i figured it out... =)

include_path was located in php.ini

it was commented out, so i de-commented it... added the path i wanted (the absolute path to the webspace root path)... restarted apache, and it seemed to work...

Reply With Quote
  #3  
Old January 26th, 2003, 09:18 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
you could do something like this..

say the root of your webdir is this

/var/wwwdir/html

and you have your config files in /var/wwwdir/config

then you could do this for your include
PHP Code:
<?
include('../config/config.inc.php');
?>

Reply With Quote
  #4  
Old January 30th, 2003, 10:32 AM
geomouchet geomouchet is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Acton, California
Posts: 2 geomouchet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
General purpose way to get root path

I got this code from somewhere else and it works like a charm to get the root path:

PHP Code:
function path_to_root($path)
   { 
   
$pathinfo pathinfo($path); 
   
$deep substr_count($pathinfo[dirname], "/"); 
   
$path_to_root "./"
   for(
$i 1$i <= $deep$i++) 
      {
$path_to_root .= "../";} 
   return 
$path_to_root


// Call it like this when you want to specify a path that starts
// from the root directory:
$path  path_to_root($REQUEST_URI); 
include(
$path.'config/config.inc.php'); 

Reply With Quote
  #5  
Old January 31st, 2003, 01:36 AM
vlasblom vlasblom is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Netherlands
Posts: 14 vlasblom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 45 sec
Reputation Power: 0
Lightbulb

Doing the trick for me is using the global $_SERVER['DOCUMENT_ROOT'] variable.

Your include would become
PHP Code:
include( "$_SERVER[DOCUMENT_ROOT]/config/header.php" ); 

This way you're not depending on the path setting in the php.ini file and is your script or application portable over various web-platforms, as long as they provide this global $_SERVER variable.

Regards,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP's include/require


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway