Jump to content

Recommended Posts

Posted

I'd like to include a few files in my scripts.

On WAMP, I've been using the document root as include path but i don't know how to do it here.

Ideally, I'd have this:

<!--?php
require_once('global.inc.php');
require_once('myclass.inc.php');

Is there a specific folder that i should put my includes in?

 

I get this error:

Failed opening required '/global.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in/home/bigpig/public_html/ajax/shelf.php on line 5

 

One more question: Will using too many includes (3) slow down execution by a lot?

Posted

The above code includes the file in the same directory.

 

You can try to place the global.inc.php and myclass.inc.php in the same directory where you have placed self.php

Posted

I wanted to avoid that. It makes everything ugly + i have different folders.

If i can have an include path higher up ( Above public_html so nobody accesses the classes directly (even though it doesn't matter) ) i'd like to use it.

 

I'm new to all this :(

Posted

You can use include for files from different folders, but the whole path to the file must be included.

Example:

/home/bigpig/public_html/(path-to-file)

And yes, include does slow down execution time, depending on the amount of includes and the size/amount of code of the included files. I think it is best to limit using include to about 3 times.

Posted

In PHP the logic is as following (source http://www.php.net/manual/en/function.include.php ):

 

* If the path starts with / then it is deemed the absolute path on the filesystem of the server

 

* If it does not start with ./ or ../ then it will look in the include_path. This is set to be . and two more system locations you cannot reach yourself.

 

* If the path does start with ./ or ../ then it is relative to the current file

 

I had some problems with included and then I started using

<code>require_once __DIR__.'/shared.php';</code>

Where __DIR__ is always the absolute path of the file in which it is used. So if you use __DIR__ in two files, the one including the other, then __DIR__ is (or can be) different for both files.

 

But prepending with ./ should be the same as __DIR__ so maybe I will give that another go myself (once I have something working I do not easily change) :-).

 

I would advice against using absolute paths: it would make it more difficult to move to a different server or subdomain.

Posted

Thanks.

I was wondering whether heliohost had a preset include path for my files. If it did, Then i could easily move hosts or subdomains without having to worry too much.

Right now i have one global_config which is in the same directory as the pages + a classes folder.

 

Thanks for your support. I have my answer :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...