...

View Full Version : Include, require, require_once



zoobie
07-30-2002, 11:35 AM
I've noticed some hosts have the include('xxx.php'); require('yyy.php'); require_once('zzz.php'); and require_once(dirname(__FILE__) . disabled.

How do I get around each?

Thanks :p

mordred
07-30-2002, 01:38 PM
I take it that they have also include_once() disabled, because that would be the most fitting alternative.

You could also try to open the files by file() or fopen() and eval() their contents, like



$fileContents = implode("", file("external.php"));
eval($fileContents);


Of course external.php must consist exclusively of valid php code, that means no opening <?php and closing tags inside etc. Sadly, if your host has all include... functions disabled, I assume they have the filesystem functions disabled as well.

On some apache servers you can set those php configuration values directly in a .htaccess file. More info about that can be found at http://za2.php.net/manual/en/configuration.php. This option can also be disabled by the server admin and depends highly on each single configuration of the server your script is running on.

For me it seems your host has a quite restrictive safe_mode configuration working (see also http://za2.php.net/manual/en/features.safe-mode.php and what *could* be done to circumvent this). Frankly, I would write them a polite email and request that they reconsider their PHP security configuration. Because include and require are essential for PHP programming, unless you want to rewrite every script of yours.

If they still refuse to change their security policy, ditch them and change hosts.

zoobie
07-31-2002, 10:49 PM
Well, I was looking for answers like "if it's include('xxx.php'); take the file xxx.php and paste it above this and remove the include('xxx.php');"

Is this correct?

What about require?
Require_once?
Include_once?

Writing hosts is a fruitless waste of time. I wouldn't dare bother.

Thanks :p

mordred
08-01-2002, 05:19 AM
Basically that's correct and your last alternative. Only make sure that you don't copy redundant code, say if one function is in include1.php and in include2.php, you only need it to copy once to your script.

About the host: That's why I pay for my hosting. Invaluable the occasional email communication with the server support.

skinme!
08-01-2002, 03:42 PM
mordred, you mentioned above that when using filesystem commands, the file to be used cannot contain PHP code itself. Is that true of include()? (i.e. can I include a file which has includes inside it?)

firepages
08-01-2002, 04:11 PM
skinme yes you can include() or require() a file with other includes in it just remember that all apths are relative to the calling file and not the included ones.

zoobie a host that has include() and require() disabled may as well not bother offering PHP hosting at all ! seriously, find another host.

mordred
08-01-2002, 05:55 PM
Originally posted by skinme!
mordred, you mentioned above that when using filesystem commands, the file to be used cannot contain PHP code itself.

No, I did not say that. What I describe was an example how to open a file and evaluate it's complete contents through the eval() function. Such a file most contain *only* php code, since eval("<php") gives you an error.

include et al are also not filesystem functions. They are language constructs, though they work in manner that relates to opening a file through the filesystem functions.

Hope that clears things up.

Ah, one thing more: You need to use <?php and ?> on included files because with the include constructs, PHP drops out of the php parsing. That's pretty handy because you can put large static HTML content into a template file and just include() it to write it to the output.

skinme!
08-01-2002, 11:29 PM
Sorry, my initial post was rather sloppily written. Thanks for clearing it up.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum