fortnox007 Posted January 23, 2011 Share Posted January 23, 2011 Hi all, I was reading a bit in the manual about the defined function. Since i have seen it being used quite a lot to disallow direct access. But one of the comments made me think if there are any alternatives to get the same. it's this comment: http://www.php.net/manual/en/function.defined.php#89886 If i read it correct it tells that defined() seems to be pretty slow. I was thinking, if that is the case what are the alternatives... Does anyone know how to interpret this comment and if there are alternatives? I am not yet a guru tofully understand the results. cheers! Quote Link to comment https://forums.phpfreaks.com/topic/225421-to-define-or-not-to-define-thats-my-question/ Share on other sites More sharing options...
trq Posted January 24, 2011 Share Posted January 24, 2011 defined check sot see if a constant is defined. There is no alternative. Quote Link to comment https://forums.phpfreaks.com/topic/225421-to-define-or-not-to-define-thats-my-question/#findComment-1164177 Share on other sites More sharing options...
fortnox007 Posted January 24, 2011 Author Share Posted January 24, 2011 Thanks Thorpe for your reply! So may i assume, if i have something like this: an index.php that includes other phpfiles the following is the way to restrict direct access to php files in the webfolder <?php define('my_constant', 1); include('anyfolder/anyfile.php'); ?> and in the included file <?php defined('my_constant')or die('bla bla bla'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/225421-to-define-or-not-to-define-thats-my-question/#findComment-1164224 Share on other sites More sharing options...
Psycho Posted January 24, 2011 Share Posted January 24, 2011 A better solution is to just put your include files in a non-web accessible folder. But, yes you could do that, or just use any variable along with isset() Quote Link to comment https://forums.phpfreaks.com/topic/225421-to-define-or-not-to-define-thats-my-question/#findComment-1164229 Share on other sites More sharing options...
fortnox007 Posted January 24, 2011 Author Share Posted January 24, 2011 Thanks for your reply mjdamato! this one is solved -edit: this was something i saw in quite some cms frameworks, which also aim at crappy shared host users, so i thought i was a good thing to know about this hehe Quote Link to comment https://forums.phpfreaks.com/topic/225421-to-define-or-not-to-define-thats-my-question/#findComment-1164233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.