Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Include, require, require_once

    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
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    PHP Code:
    $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.
    Last edited by mordred; 07-30-2002 at 12:40 PM.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?)
    skinme.net / v2.php (design nearly completed)

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    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.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, my initial post was rather sloppily written. Thanks for clearing it up.
    skinme.net / v2.php (design nearly completed)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •