SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    0 Post(s)
    0 Thread(s)

    a few questions.

    - if i'm in a Subfolder i need to include a file from the main folder
    i'm using $path = $_SERVER['DOCUMENT_ROOT'];
    but on my pc there's more than one website therefor i have to add
    an additional folder to that path
    $path ="$path/MYwebsite/";
    everything is good but every time i edit those files and i have to upload it
    on a server, i have to remove that last code.
    is there an easier way?

    - what's the difference between die() and exit?

    -If i have a few queries but i want to execute all of them only if none of them
    fails, is there a way of doing that? for example if i create many database
    tables but i don't want the script to run if it fails creating one of those tables.
    (without adding a code for removing all tables if one query failed)

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    You should let PHP work out where the include folder is.

    A list of permitted folders can be put in your php.ini file.

    Look for the line include_path.

    When it sees include() PHP then goes through each of those folders looking for the file to include for you. There is nothing wrong with creating folders inside those folders and stashing include files in there.

    For example if your include_path is this:

    include_path "c:/inetpub/includes/"

    you can have a file in it called:


    It doesnt matter where a page is called from , how deeply nested in directories on your website, it'll find and include that file with:


    Even from here:

    Then, as long as your online php.ini file says something like:

    include_path = ".;/var/www/includes"

    That is where you stick and all your scripts will be able to find it - just like they did on apache/IIS on your localhost

    When you start getting jiggy with it, and have hundreds of include files, then you can sort them into folders.

    include_path "c:/inetpub/includes/"

    Leave the ini file the same ...

    But create directories in includes like this:


    Then your include instruction can look like this

    include( "my_new_project/crud.class.php");


  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    0 Post(s)
    0 Thread(s)
    I need other people to download that website therefore i can't just change
    the php.ini manually.
    what i've done is the following

    PHP Code:
    $path $_SERVER['DOCUMENT_ROOT'];
    $splitted split('/'$folders);
    $splitted as $key => $value) {
        if (empty(

    while (!
    file_exists("$path/rootfolder.php") && $x>0) {
    $path .= '/'.$splitted[$a]; 
    ini_set('include_path'$path '/includes'); 
    but it looks kinda silly and long for a single include.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    0 Post(s)
    0 Thread(s)


Posting Permissions

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