Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Defining "Constants" to prevent direct file access

Featured Replies

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?

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

  • 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.

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

  • Author

Surely it can't possibly hurt to have a fail safe, a file might get misplaced or something sometime and you never know...

  • 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?

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

  • Author

Yep that's what I've got so far, just having to go through my whole site now changing everything!!!

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.

  • 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.

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.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.