+ Reply to Thread
Results 1 to 6 of 6

Thread: Disallow direct access..

  1. #1
    Fedlerner's Avatar
    Fedlerner is offline Retired Fedlerner is an unknown quantity at this point
    Join Date
    Aug 2006
    Location
    Buenos Aires, Argentina
    Posts
    12,923

    Exclamation Disallow direct access..

    Hi!
    I want to disallow the access to some files, cause i want to make a header.php, footer.php etc, and i don't want them to be accessed directly...
    Which is the PHP code for that?? :nuts:

    Thanks,
    fedlerner
    Federico Lerner
    Former x10Hosting Administrator - Staff Manager

  2. #2
    Micro is offline Retired staff (11-12-2008) Micro is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    West Midlands
    Posts
    1,301

    Re: Disallow direct access..

    you can use file_get_contents, include() or require() (Perhaps put them in a randomly named folder)...
    Micro

  3. #3
    Fedlerner's Avatar
    Fedlerner is offline Retired Fedlerner is an unknown quantity at this point
    Join Date
    Aug 2006
    Location
    Buenos Aires, Argentina
    Posts
    12,923

    Re: Disallow direct access..

    Sorry, i didn't expressed myself well..
    What i do is have for example the index.php and the header.php and footer.php
    i use the include() function to include the header.php and the footer.php in my index.php file and all my other files.
    What i want to know is the PHP code to don't allow users to access the file directly if the tipe mydomain.com/header.php...

    In PHP-Nuke for example, they use this code if you want to access a module directly:
    Code:
    if ( !defined('MODULE_FILE') )
    {
    	die("You can't access this file directly...");
    }
    I don't really know too much php. I added this code to my header but as it's only for PHP-Nuke when i open the index.php it also appears "You can't access this file directly..."

    Does someone know how to do it?
    Federico Lerner
    Former x10Hosting Administrator - Staff Manager

  4. #4
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Re: Disallow direct access..

    You've just answered yourself in you last post. You can define a constant in the file which you are "including" header.php from. Then in your seperate files, just check to see if that constant has been defined, which is what phpnuke is doing. Place this before the includes in all the files which you are including other files.

    PHP Code:
     define('IN_MY_SITE'true); 
    Then place this in all the include files.

    PHP Code:
    if(!defined('IN_MY_SITE'))
      {
        die(
    "Please don't access this file directly.");
      } 
    This means that if the constant "IN_MY_SITE" has not been defined: i.e. The file has not been included by another PHP script, it won't allow you to view the rest.
    Last edited by Woolie; 09-29-2006 at 11:51 AM.

  5. #5
    jaint is offline x10 Sophmore jaint is an unknown quantity at this point
    Join Date
    Jul 2006
    Posts
    174

    Re: Disallow direct access..

    you could still access it I think, if you accessed it like this (not sure if it'll work) :

    header.php?IN_MY_SITE=true&defined=IN_MY_SITE (of course you'd need to know that probably).

    I'm trying to something similar but I'm not including the file, so it's a bit more difficult.

    Post Message

    ----------------------------------------------------------------------------------------


  6. #6
    Fedlerner's Avatar
    Fedlerner is offline Retired Fedlerner is an unknown quantity at this point
    Join Date
    Aug 2006
    Location
    Buenos Aires, Argentina
    Posts
    12,923

    Re: Disallow direct access..

    Oh thanks Woolie!! It works now!!! :D
    jaint, i tryed puting header.php?IN_MY_SITE=true&defined=IN_MY_SITE and it doesn't acces it, it appears the message i put "You can't access this file directly..."

    Thanks to all!!!
    fedlerner
    Federico Lerner
    Former x10Hosting Administrator - Staff Manager

+ Reply to Thread

Similar Threads

  1. Cannot Access FTP?
    By echo_unlimited in forum Free Hosting
    Replies: 37
    Last Post: 09-08-2006, 07:23 PM
  2. FTP Access
    By Turbulence in forum Free Hosting
    Replies: 1
    Last Post: 12-29-2005, 02:08 PM
  3. Root and Shell Access
    By Wai_Wai in forum Free Hosting
    Replies: 5
    Last Post: 09-09-2005, 01:40 AM
  4. Can not access the site...Page not found
    By repusmod in forum Off Topic
    Replies: 2
    Last Post: 05-18-2005, 11:19 PM
  5. External SQL Access
    By Origin in forum Free Hosting
    Replies: 0
    Last Post: 03-25-2005, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers