hi, i'd like to include some templates outside of my webroot directory, simply so they can't be run publicly. i'm trying to set the "include_path" to allow me to do this.

i'm using a public server so this might be a permissions issue.

i have a template in the webroot which does this:

<?
ini_set("include_path","./../_php");
include("main.php");
?>

i want it to drop down a level from the webroot, then into my "_php" directory which contains my main php files.

if i set include_path to be any subdirectory of the webroot the templates work fine but any outside of the webroot folder return this error:

failed to open stream: No such file or directory in d:\InetPub\development\test.php on line 3
Failed opening 'main.php' for inclusion (include_path='./../_php')

is there something else i need to set in PHP, or is this a folder permissions issue? or am i just being stupid?

thanks!

    Try to use absolute paths, either in ini_set or in include (you won't need to set include_path then).

      Like wilku say.
      Use
      C:/folder/folder - in Windows
      /usr/local/apache - in Linux

      Or change include path in your php.ini
      You can see what syntax is used, and you use same sort of expression

      To see your present, your current include path setting:
      make a phpinfo.php

      <?php
      
      phpinfo();
      
      ?>

      Run this page, and search for 'include' in that page.
      I always keep phpinfo.php in my php scripts working folder.
      So I can look my php.ini settings up easily and fast.

        thanks. i've tried include("d:\InetPub\_php\main.php")

        i also tried ini_set("include_path","d:\InetPub\_php");
        include("main.php");

        are these looking correct?

        also tried various combinations of using forward slashes without the "d:".. grr!

        could it be that my host's restricted my PHP to be using my public folder only and PHP isn't being allowed to read from anywhere else? is there a way i can test permissions in PHP?

        thanks again..

          thanks.. phpinfo() says my include_path is ".;C:\php5\pear"

          just noticed something, if i output this:

          echo $_SERVER["SCRIPT_FILENAME"]

          the directory my hosts have actually used is the name of the website, eg "d:\inetpub\phpbuilder.com\web" - could it be that the dot is screwing things up?

            "." is minimal include path
            semicolon ; is used for to separate more than one path

            try for example:
            ".;C:\php5\pear;D:\inetpub\pathto\yourwebspace"

            always putting a semicolon in between paths
            D:\ should be used, if your webdocuments are in D:\ drive
            else use C:\

              thank you halojoy & wilku

              i think it's something weird my hosting company has done.

              they've set up the website to run under:

              d:\inetpub\phpbuilder.com\webroot\

              but when i output SCRIPT_FILENAME it just says "d:\inetpub\phpbuilder.com\test.php".

              there's no "\webroot" directory in the php reading, yet when i FTP i have to use "webroot" as my public folder.

              confused! can't speak to them til monday now.. oh well!

              thanks for helping though..

                There is something webservers, apache and others, use
                called 'virtual hosts'
                They do not exists as folders, but you can surf there anyway

                Yes, this will be sorted out once you talk to your webmaster
                'Dont Worry! Be Happy!'

                  thanx

                  yeah i'll be happy now cos i'm gonna switch off & get a takeaway..

                  : )

                    Write a Reply...