thinkphp5Ò»Ñùƽ³£¼ÓÃÜÄÄЩÎļþ
ÔÚ¾ÙÐÐ thinkphp5 Ó¦Óð²ÅÅʱ£¬ÎªÁËÔöÌíÓ¦ÓóÌÐòµÄÇå¾²ÐÔ£¬ÎÒÃÇÒ»Ñùƽ³£»á¶ÔijЩÃô¸ÐÎļþ¾ÙÐмÓÃÜ¡£±¾ÎĽ«ÏÈÈÝ thinkphp5 ÖÐÒ»Ñùƽ³£ÐèÒª¼ÓÃܵÄÎļþ£¬ÒÔ¼°¼ÓÃÜÒªÁì¡£
Ò»Ñùƽ³£ÐèÒª¼ÓÃܵÄÎļþ
ÉèÖÃÎļþ
ÉèÖÃÎļþÖаüÀ¨ÁËÊý¾Ý¿âÃÜÂëµÈÖ÷ÒªÐÅÏ¢£¬²»¼ÓÃÜÈÝÒ×±»ËûÈË»ñÈ¡£¬Ôì³ÉÊý¾ÝÇå¾²ÎÊÌâ¡£
¿ØÖÆÆ÷Îļþ
¿ØÖÆÆ÷Îļþ°üÀ¨Á˳ÌÐòµÄÓªÒµÂß¼´úÂ룬²»¼ÓÃÜÈÝÒ×±»¾ºÕùµÐÊÖ»ñÈ¡£¬µ¼ÖÂӪҵй¶¡£
Ä£×ÓÎļþ
Ä£×ÓÎļþ°üÀ¨ÁËÊý¾Ý¿â²Ù×÷µÄ´úÂ룬ÆäÖаüÀ¨Á˶ÔÊý¾Ý¿âµÄÔöɾ¸Ä²é²Ù×÷£¬²»¼ÓÃÜÈÝÒ×±»ËûÈË»ñÈ¡£¬µ¼ÖÂÊý¾Ý¿âÊý¾Ýй¶¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÊÓͼÎļþ
ÊÓͼÎļþÖаüÀ¨ÁË HTML Ä£°å´úÂ룬²»¼ÓÃÜÈÝÒ×±»ËûÈË»ñÈ¡£¬±¬·¢Çå¾²ÎÊÌâ¡£
¼ÓÃÜ·½·¨
ʹÓüÓÃÜÆ÷
ÔÚ ThinkPHP5 ÖУ¬¿ÉÒÔʹÓà Swoole ÌṩµÄ¼ÓÃÜÆ÷£¬¶ÔÖ¸¶¨µÄÎļþ¾ÙÐмÓÃÜ¡£
¼ÓÃÜ´úÂëʾÀý£º
use Swoole\Process; $encrypt_files = [ __DIR__ . '/../application/config.php', __DIR__ . '/../application/database.php', __DIR__ . '/../application/admin/controller/User.php', __DIR__ . '/../application/admin/model/User.php', ]; // ¼ÓÃÜÃÜÔ¿ $key = "1234567890"; // ÏÂÁîÐвÎÊý $argv = [ 'swoole_encryption', // ³ÌÐòÃû 'password', // Óû§ÃÜÂë 'backend', // Óû§½ÇÉ« ]; foreach ($encrypt_files as $file) { $process = new Process(function () use ($file, $key, $argv) { // Ö´ÐмÓÃܲÙ×÷ $encrypted = \Swoole\Encryption\Encrypt::setKey($key) ->encrypt(file_get_contents($file)); // ½«¼ÓÃܵÄÄÚÈÝдÈëµ½ÔʼÎļþÖÐ file_put_contents($file, $encrypted); // Ö´ÐÐÏÂÁîÐÐÏÂÁî $cmd = implode(' ', $argv); exec($cmd); }); $process->start(); }
µÇ¼ºó¸´ÖÆ
×Ô½ç˵¼ÓÃÜ·½·¨
³ýÁËʹÓüÓÃÜÆ÷Ö®Í⣬ÎÒÃÇ»¹¿ÉÒÔ×Ô½ç˵¼ÓÃÜ·½·¨¡£¿ÉÒÔ¶ÔÎļþÄÚÈݾÙÐÐ MD5 ÊðÃû£¬È»ºó½«ÊðÃûºóµÄÄÚÈݺÍÔʼÄÚÈÝÒ»ÆðдÈëµ½ÎļþÖС£ÔÚÔËÐÐʱ£¬¶ÁÈ¡ÎļþÄÚÈÝ£¬±ÈÕÕÊðÃûºÍÔʼÄÚÈÝÊÇ·ñÒ»Ö£¬´Ó¶øÑéÖ¤ÎļþµÄÍêÕûÐÔ¡£
¼ÓÃÜ´úÂëʾÀý£º
/** * ¼ÓÃÜÎļþ * * @param string $file Îļþ·¾¶ * @param string $key ¼ÓÃÜÃÜÔ¿ */ function encryptFile($file, $key) { $content = file_get_contents($file); $signature = md5($content . $key); $encrypted_content = $signature . $content; file_put_contents($file, $encrypted_content); } /** * ½âÃÜÎļþ * * @param string $file Îļþ·¾¶ * @param string $key ¼ÓÃÜÃÜÔ¿ * * @return boolean */ function decryptFile($file, $key) { $content = file_get_contents($file); $signature = substr($content, 0, 32); $data = substr($content, 32); $md5 = md5($data . $key); if ($md5 == $signature) { file_put_contents($file, $data); return true; } else { return false; } } // ´ý¼ÓÃܵÄÎļþÁбí $files = [ "/path/to/config.php", "/path/to/controller/User.php", "/path/to/model/User.php", ]; $key = "1234567890"; // ¶Ôÿ¸öÎļþ¾ÙÐмÓÃÜ foreach ($files as $file) { encryptFile($file, $key); } // ¶Ôÿ¸öÎļþ¾ÙÐнâÃÜ foreach ($files as $file) { decryptFile($file, $key); }
µÇ¼ºó¸´ÖÆ
×ܽá
ͨ¹ý¶ÔÃô¸ÐÎļþ¾ÙÐмÓÃÜ£¬¿ÉÒÔ°ü¹ÜÓ¦ÓóÌÐòµÄÇå¾²ÐÔ£¬±ÜÃâÊý¾Ýй¶¡¢´úÂ뾺ÕùµÈÎÊÌâ¡£ÔÚ¼ÓÃÜÎļþʱ£¬ÎÒÃÇ¿ÉÒÔʹÓõÚÈý·½¼ÓÃÜÆ÷£¬Ò²¿ÉÒÔ×Ô½ç˵¼ÓÃÜ·½·¨¡£ÎÞÂÛÄÄÖÖ·½·¨£¬¶¼ÐèÒª¼ÓÃÜÃÜÔ¿°ü¹ÜÊý¾ÝµÄÇå¾²ÐÔ¡£
ÒÔÉϾÍÊÇthinkphp5Ò»Ñùƽ³£¼ÓÃÜÄÄЩÎļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡