Mobile app version of vmapp.org
Login or Join
Yeniel560

: What is an easy way for disabling a file temporary? 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

@Yeniel560

Posted in: #WebDevelopment

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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel560

1 Comments

Sorted by latest first Latest Oldest Best

 

@RJPawlick198

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


debug.php

<?php

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


or

<?php

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

// do the stuff
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme