开发者

PHP file that should run once and delete itself. Is it possible?

开发者 https://www.devze.com 2022-12-25 22:17 出处:网络
Is it possible to create a 开发者_运维知识库PHP file that runs once with no errors and deletes itself?<?php unlink(__FILE__); ?>

Is it possible to create a 开发者_运维知识库PHP file that runs once with no errors and deletes itself?


<?php unlink(__FILE__); ?>


Here's a great way of ensuring the script gets deleted, no matter if intervening code calls exit() or not.

class DeleteOnExit
{
    function __destruct()
    { 
        unlink(__FILE__);
    }
}

$g_delete_on_exit = new DeleteOnExit();


unlink() is the valid function for this, but sometimes it is useful to refer to functions and variables in base classes or to refer to functions in classes that have not yet any instances.

class SelfDelete{
    public static $obj;

    function __destruct(){
        unlink(__FILE__);
    }

    function _self(){
        self::$obj = new SelfDelete();
    }

}
Auth::_self();


If you can't use unlink() try create .htaccess

<Files "install.php">  
  Deny from all
</Files>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号