Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a file called debug.php and I want to use it only when I am testing scripts.

  • How can I disable the file securely?

I'm used to change it to a txt file. But I wonder what other users think is the best method.

share|improve this question
up vote 3 down vote accepted

Change it to a text file doesn't disable it. And if it is called from somewhere you'll get errors if you have error_reporting enabled. And it might be visible for clients of you change the extension, because a .txt file will not be parsed using PHP.

Since you want the file to only be used when in 'debug mode' I would simply either wrap it in a if-statement or if it is a function add a if-statement with a return void. And set a debug mode constant to be able to switch easily. E.g.

define('DEBUGMODE', true); // set this somewhere in your project as soon as possible



if (DEBUGMODE === true) {
    // do the stuff



debugFunction() {
    if (DEBUGMODE === true) return;

    // do the stuff
share|improve this answer
+1 for still being visible: the server will almost certainly just push a .txt file source to the browser, which is arguably more dangerous than actually executing (depending on what the file does). – msanford Jan 26 '12 at 18:12
But I've got a file that I use as a test file. E.g. to manually make a pass hash. I want to use a 'change-file-name-solution'. What would you suggest? – SuperSpy Jan 26 '12 at 18:51
I still don't see why you would change the name, but if you really want to go for the name change thing you can name it anything you want as long as the extension stays the same. – PeeHaa Jan 26 '12 at 19:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.