WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2004, 10:53 PM
WebProWorld Member
 

Join Date: Oct 2004
Posts: 57
brendgard RepRank 0
Default php require()

OK, I'm spinning my wheels looking for what I need, so I was hoping somebody could give me a hand and or at least give me a point in the right direction.

The manuals all tell me the proper use of require() in php is

require "somefile.php";

But what I can't seem to find is how to point it at another directory, particularly one a couple of levels up. I have a php file 2 levels down that I want to have call a file that's not in the same directory, but is locate in the root directory 2 levels up. I've tried

require "http://domain.com/somefile.php";

and

require "domain.com/somefile.php";

Even if it's only 1 level up it would be of great help.

I'm not the worlds greatest php programmer so I'm thinking it's probably easy, but I really could use some pointers. Thanks.
__________________
http://script-place.com - http://stocksinvestorsite.com
http://GamersGO.com- Add your arcade to the list!
Reply With Quote
  #2 (permalink)  
Old 12-14-2004, 03:04 AM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
cyanide RepRank 0
Default

Try
Code:
require ("../somefile.php");
__________________
|
Web Hosting Guru
| Need Help For Your Forum?
Reply With Quote
  #3 (permalink)  
Old 12-14-2004, 02:40 PM
WebProWorld Pro
 

Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

for simplicity.. and sanity..

You may want to create an .htaccess file in the top level directory / web root.. (the first level of the web site where you would put your index file.)

put the following on one line in the .htaccess:
php_value include_path .:/path/from/root/to/here

Where /path/from/root/to/here is
/home/vhosts/domain/var/www/html or something like it.

php will then search the current directory, and if the file is not there it will look in the web root of that site.
You can then add directory paths from web root to your include/require statements.
ie.
require("subdirectory/file.php");
in your case..
require("level1/level2/somefile.php");

This is handy if you ever change want to move your code to another machine with a different file structure.
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #4 (permalink)  
Old 12-15-2004, 12:21 PM
WebProWorld Member
 

Join Date: Oct 2004
Posts: 57
brendgard RepRank 0
Default

Thanks. I never would of though of those. Funny thing is, I retried the

require ("http://domain.com/somefile.php")

again and this time it worked. It's got me scratching my head as to what's going on. I will definatly have to try the other ways though, I'm not sure how long this way will hold up. Maybe somebody was messing with the server configuration at the hosting company or something. Or maybe, more likely knowing me, I forgot the () the first time lol.

Thanks again for the ideas though, most appreceated.


An adendum to what was posted up above.

I just thought you might want to see what you were giving advice on. What's going on is we are looking for people to do articles for our site: weekly, monthly, tutorials, paid courses etc. We have one person who is interested and they wanted an example, so we put together this

http://websitegurus.us/articles/bren...brendgard1.php

Wanting to save heartburn, time etc, not wanting to have to rewrite everything from scratch everytime, we put together a template to copy and paste it into each time.

http://www.websitegurus.us/articles/.../template1.php

The script that helps keep right clicking off is loaded into a file that is called by require(). The advertising on the left is a seperate file also loaded by require(), and the author's info by yet another. It saves time(not to mention disk space) because we don't have to type it all out each time, and we only have to edit one file to change the ads ect.

Not pretty spiffy by the standards of somebody who's a pro at it, but for somebody who has more experience with the infrastructure and hardware than with coding, I thought it was ok. I'm liking PHP more and more lately.

Thanks for the pointers again.
__________________
http://script-place.com - http://stocksinvestorsite.com
http://GamersGO.com- Add your arcade to the list!
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0