Results 1 to 5 of 5

Thread: Protecting Includes Folder -[RESOLVED]-

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Resolved Protecting Includes Folder -[RESOLVED]-

    I have a folder which holds all the files which I'm including in the main scripts. Thing is these includes aren't meant to be run. what ways are there to stop people accessing/running them. I tried changing the folders permission to only Owner & Group can read but I had to switch it back cos it wouldn't allow me to include then.
    I was thinking about .htaccess files but i'm not sure how to make them or if that would even work. My host gives a wizard for making them but I'd find it better if I knew how to make them myself .
    Last edited by Electroman; Nov 15th, 2004 at 05:50 PM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Only three more to go

    There are a number of ways to protect the include files.
    • Put them outside the website root directory. That way there is no way the user can access them.
    • Change the permissions so only the the PHP process can access them, this only works under UNIX when run with the SuExec CGI wrapper, as most of the time PHP will run in the same process space as the web server.
    • Always name your include scripts with a .php extension, don't fall into the trap of using .inc, becuase if they were to be served to the user by accident a .inc file would simple be dumped, hence all your source code and passwords.
    • As a final line of defence, should a user execute the script directly. Define a constant in your main script, and check it exists in the include file before allowing it to run:

      main.php
      PHP Code:
      <?php
      define 
      ('IN_APP'1);

      include(
      'myinclude.php');
      ?>
      myinclude.php
      PHP Code:
      if (! defined('IN_APP')) {
          die(
      'Thie script cannot be run directly.');

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Easy enough with a .htaccess file. Just need two lines:

    Order allow,deny
    Deny From all
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Well I'd named them all xxx.inc.php As for the define thing thats an idea. Mind if i'm making a .htaccess file I shouldn't need that? IS there any site you know of that I can find out more about .thaccess files?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

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



Click Here to Expand Forum to Full Width