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
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
you can use file_get_contents, include() or require() (Perhaps put them in a randomly named folder)...
Micro
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:
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..."Code:if ( !defined('MODULE_FILE') ) { die("You can't access this file directly..."); }
Does someone know how to do it?
Federico Lerner
Former x10Hosting Administrator - Staff Manager
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.
Then place this in all the include files.PHP Code:define('IN_MY_SITE', true);
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.PHP Code:if(!defined('IN_MY_SITE'))
{
die("Please don't access this file directly.");
}
Last edited by Woolie; 09-29-2006 at 11:51 AM.
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
----------------------------------------------------------------------------------------
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