August 27, 201214 yr I started off creating a constant for every individual script that my site has, but then I was thinking that it would probably be just as secure if I had one constant for my whole site and checked it in every script that is called. Would this be ok or would it be better to have individual ones?
August 27, 201214 yr If you're using an MVC/boot strap type application, then one defined variable in the index.php will be enough. You could also just have a directory with all your restricted scripts in, and block them using .htacess with deny from all
August 27, 201214 yr Author I'm planning on using the .htaccess method as well, I need to first do a bit of restructuring for it to work. I'm not using any kind of MVC, created it all myself.
August 27, 201214 yr I see. If you have the .htaccess method, then defining constants is pointless, as you've already protected them as well as you can. The constants will be of no value to your security
August 27, 201214 yr Author Surely it can't possibly hurt to have a fail safe, a file might get misplaced or something sometime and you never know...
August 27, 201214 yr Surely it can't possibly hurt to have a fail safe, a file might get misplaced or something sometime and you never know... to me the constants would be the better way to go
August 27, 201214 yr Author to me the constants would be the better way to go So would one constant for my whole site work then check it on each page?
August 27, 201214 yr So would one constant for my whole site work then check it on each page? just define a constant on each page a person would visit like this define('SITE_ACCESS',true); then in your include files you wanna prevent direct access just check if the constant is defined, if its not use a die() statement
August 27, 201214 yr Author Yep that's what I've got so far, just having to go through my whole site now changing everything!!!
August 27, 201214 yr Remember that you can also include files from above your www / public_html folder, so the "secret" file you're calling isn't even in the public directory of the server.
August 27, 201214 yr Author My problem at the moment is whilst in development my live testing server is a free service and doesn't allow me to put folders outside the document root. I'm gonna start looking into some paid hosting services now though anyway so I will gradually move over to this, and then probably use all 3 methods, can't have enough security IMO.
August 27, 201214 yr You could download mamp/xampp(which is free) to your own machine to enable a local server. I do most of my development using mamp so I am able to test file structure as well as code. The one drawback I've come across is that it is somewhat complicated to configure the localhost to send emails - but I bet someone somewhere on this forum could explain it.
August 27, 201214 yr If you're looking at paid hosting I'd recommend sorting that out first and then setting up your own local server so it matches, there are all sorts of subtle differences that could make something work just fine on your local server but fail in strange ways on your live server.
Create an account or sign in to comment