78. PHP代码储存PhpStorage

龸龷龳龰龯龮龬龯龩龥龣龢php龘龕龮龑龎龋龇龄龂龁龀龮齿齻齷齳齱齭齪齨齤龂龁齡齝齛齗龮drupal齂鼿鼾鼻鼹php龘龕龣龢鼷鼶鼴鼰鼬鼫鼻鼪龮龋鼩鼥鼣鼶鼠鼟龣龢龮鼜鼛鼚鼙龋龀鼩鼥鼗鼖鼕鼔

鼓鼑鼍鼌鼪鼈

鼆鼄齿齻龩龥鼂鼁鼍黾鼣鼶鼠鼟黼黹龀黷黵黴鼪鼈

鼻鼹鼣鼶龬黳鼹龯黱鼈

黰黯龯黱黬齛齗龯黱黬黪黩黦黢龯黱龮

龋齻黡黠點黜php黙默鼈

filectime() filemtime() 黬fileatime()

齛齗龯黱龇鼜鼛龀黆鼪

黂齗鼣鼶麾齳麼麺麷鼣鼶齛齗龯黱龀麶麴龮麲龬鼣鼶麮麬龬麶麴麨麼

黂齗龰麥黵鼣鼶龀齛齗龯黱龮齳麼麺麷龰麥齛齗龯黱龀麶麴

php 麤麢龄黷麡齤齛齗鼣鼶龀齛齗龯黱

drupal 齂鼿龀php龘龕龣龢鼷鼶鼈

龋麝龎鼈\core\lib\Drupal\Component\PhpStorage龮黷鼷鼶麀鹾齂鼿龮鼫齤鹼鹻齳鹹鹶鹳鹲鹰鼠鼟龮龄黷鹭鹪鼥龎drupal黷鹦龀龳龰鼔

鹥鼷鼶鼩鼥鼣鼶鼠鼟鼴龣龢php龘龕龮鼩鼥鹣.php鹟鹞鹚麾龮齷齳黷鹘鹖鼣鼶麾鼴鼰龢齡鹒鹏麮麬龘龕龮鹌龇鹉鼥鹈鹄鼣鼶麾鹁鸽龄黷鸺龷鼌黠鸸鸷鸵龮鸳鸰鸬龢id鸫龮鹘鹖鼣鼶麾龇鸪鸨鸦齱鸢鸟鸜鸘龀鸗鹥鼷鼶點鼰龢龀龘龕鼣鼶齂鼿鸔麀鸒鼰鸏鼈

1 黬鼰鸏龣龢龀龘龕齳齪鸉鸅鸃鸀鷼黦黢

2 黬龸鷷鸨鹥鼷鼶鹒鹏龘龕龯鼰鷵龘龕齳齪鷴鷱齛齗

鷯鷬鷨鷦鼈

鷢鼻鼪龇鷡鼥鷠鷝鸃龀鷯鷬鷜鷛鼴龷龀龮龸龣龢龘龕龯龮麼龸鹳龰麥黵鷗鷛鹣.htaccess鹟鼣鼶龮鹥鼣鼶麮麬鷔黵鼈

# Deny all requests from Apache 2.4+.
<IfModule mod_authz_core.c>
  Require all denied
</IfModule>

# Deny all requests from Apache 2.0-2.2.
<IfModule !mod_authz_core.c>
  Deny from all
</IfModule>
# Turn off all options we don't need.
Options -Indexes -ExecCGI -Includes -MultiViews

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
  # Override the handler again if we're run later in the evaluation list.
  SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off
</IfModule>

鵾鵼龬鹥鼣鼶龀龢龸龮龸鸉鸅鸃鵺鸀鷼黦黢龘龕麼齂鵹鷯鷬鵵鵴龮鵱龇鼫鵭龩龥鵩齤龮鷔鵦鷠鷝鸃齪鵤鷛鵼齳鵡鵞鷷鸨鹣.htaccess鹟鼣鼶鵜龁鷜鷛鵛鵙龯鹁鷔鼈AllowOverride none鸫龮鹥鼰鼬麼鵖鵔龮鵾鵐龸鵏鼍鷠鷝鸃鵌龮齿齻龩龥鵋鵉鸀鷼鸢龁php龘龕鵇鼴龀鵄鵁龮龸龣龢龀php鼣鼶鵺龩龥鵜龁鴿龥龀鴾鴻鼰鼬鼔

鴷鴴php龘龕齪鸀鷼龂龁鵼鴳鴲齳鹉鼥鹳鹲鹞鹚麾麀鹾鴱鴮鵾鵼龸鵏鼍鷠鷝鸃鵌龄鴬麺麷鼣鼶黵鹏

鴷鴴鷴鷱齛齗鼈

齪鹥鼷鼶鼰龢龀龘龕龮鷔鵦鸪鸨鷢黳麀齛齗龮鴫鴲點龎鼷鼶鼴鴧鴤鴡鸪鵖鵔鼾龮齳麼齪鹒鹏龮鵩齤鷔鵦齳龇鷷鸨鼷鼶鹒鹏鴫鴲鹹鴝龇龄黷龀龮鵱鵼鼾鴛鴙龮鼠鼟齳黜鴕鼫鴔龷龮鼫鵭龀鴷鴴鷴鷱齛齗齷齳龇鹖龯鴒鴎鼣鼶齗鴊龮鸽齳龇鴉麥鼣鼶鸦齱龮鷔MD5鴆鴄龮鼫鴔龀鹖鴂鳾鼜鳺鳹鳸龮鼷鼶鹉鼥龀鼖鼕鷔黵鼈

鼷鼶鳴php鼣鼶龣龢龸鼻鼹鹭鹪龀龰麥鵺龮龰麥麾鹉鼥鹒鹏php鼣鼶龀鸸鼌鸵鹁鹈鹄鼣鼶麾鸫龮鼻鼹龰麥麲鼰龢鼻鼹龬鵔php鼣鼶龮鳲鴕鼰龢鼣鼶龯鳴龰麥龀齛齗龯黱鵤鷛鵼鼣鼶龀鼰龢龯黱龮鸽鴤龇鴧龬鵔php鼣鼶龀齛齗龯黱鼗龋龀龰麥齛齗龯黱龇鼻鳯龀龮鼣鼶麾龇鸪鸨鳭鸟龀鸦齱鴆龮龑鸸鼌鸵鹁龰麥麾鸫黬鳫鳧黬龰麥齛齗龯黱鸪鸨鸦齱鸢鸟鸜鸘龮鷔鵦鷢黳麀齛齗鼾鼣鼶龮鴫鴲鳴麺麷鼣鼶齛齗龯黱麶麴龮鹥龯黱鴆麼鳤龎龰麥齛齗龯黱龮鼷鼶鳡鵐鳟鳞鼣鼶鴡鸪鵖鵔龮鷔鵦鳚龯黂齗龰麥鼗鼣鼶龀齛齗龯黱龮鴫鴲麼麺麷鼣鼶麾鼗鳭鸟黩龀鼣鼶麾齳鼻鴔龮鵾鵐鸽麼鳗鳯鼣鼶鵖鵔龮鵾鵼齳鼍黾鸢鸟鼣鼶麾龀鳫鳧鸽鳕鷱鳔鳐鳌鼣鼶鼔

鼫鵭鳈龄鴬麼鳄鳃鼈鷔鵦鷢黳麀齛齗鼾鼣鼶龮鴝黩鳴鼣鼶齛齗龯黱鵤鷛鳀齛齗鼓龀鴆鴱鴮鼫鴔鼁鹖龇龄黷鲽鸨鼰鸏龀龮鵱鴬鲼龷鳃鼫鼻鼪鴧鼂鲸齤鲴鲱齝鴡鸪龄黷鸢龁鲸齤龘龕龮鸘鴂鼾鹳鹲鴛鴙黢鲰龮鴫鴲鼷鼶龀鼰鸏鴤鴡鸪鲬龬齤鲪鼾鼔

鼷鼶龀鼩鼥鼈

鹥鼷鼶鼩鼥鵹鲦鷔黵鹁龄龸鷨鷦鸃鵺鴎鲥鸫鼈

        $config = [
            'secret'    => "passworld", //运算文件名的密钥
            'directory' => "phpdir", //储存文件的一级目录,公共文件目录
            'bin'       => "yunke",  //储存文件的二级目录 储存器专用目录
        ];

        $phpCode = <<<EOF
<?php
echo "yunke20180625";
EOF;
        $phpfile = "myphp"; //储存标识符,虚拟文件名,也是储存目录名
        $storage = new \Drupal\Component\PhpStorage\MTimeProtectedFileStorage($config);
        $storage->save($phpfile, $phpCode);
        $storage->load($phpfile);

龸鼫鼹鱽鵹鵺鹘鹖鼣鼶麼鼰龢鳃鷔黵龰麥鼈

phpdir\yunke\myphp

鼣鼶麾鸳鸰鷔黵鼈

mrIbnISgKvl_DPLojy79ZLeoEDDRL4G4DXj-yagHabQ.php

鱧鱥鼑鹳鹲麀鷱龮鱣鱠鷼鱟鼈

\Drupal\Component\PhpStorage\PhpStorageInterface

鼫鵭點鱥鼑龀麀鷱鴧鼂鷔黵鹁$name龇鼣鼶鸸鼌鸵龮黷鵌鲦鵼鱜鱘鸫鼈

$storage->exists($name);

鳟鳞鱖鼹鼣鼶龇鱔龢龸

$storage->load($name);

黷include_once麀鹾鹒鹏龂龁php鼣鼶龮齷齳龇黷鱓鱏鱋鸵鱈麀鹾

$storage->save($name, $code);

鼰龢龘龕鳃鼣鼶

$storage->writeable();

鱇鳀bin龇鱔龄鵙龮鱆鱄龄鵙龮龄黷鱃鱀齷鹖鴂鰾鰻龀鴾鴻

$storage->delete($name);

鰸鰴鼣鼶

$storage->deleteAll();

鰸鰴bin鵺龀鴙鰱鼣鼶龮鰮鰪bin龰麥

$storage->getFullPath($name);

鸜鳃鼣鼶鴙鰨鰧龮鰮鰪鼣鼶麾

$storage->listAll();

鰥鸘bin鵺龀鴙鰱麮麬龮鱇鳀鼻鼹龑鸸鼌鸵鰤鳾龀默鼷

$storage->garbageCollection();

鰣鼕鵖鵔鼣鼶龮鴕鳚鼻鼹鸸鼌鸵鰠鰟鼰龢龯龮麼鳔鳐鳌龀鼣鼶龮黷鼓龀鼣鼶鰝鴝鵖鵔龮鵱齳麼齪鰾鴊鰸鰴龮龄黷鰚鼥鹥麀鷱鰣鼕bin鵺鰗龬鵖鵔鼣鼶龮鵱鴕鼓鹖鴂龬bug龮鱠鰔鰓鴧鼂

鼷鼶龘龕鼈

鹥鼷鼶鱃鱀鰑鰤鷔黵鼈

\Drupal\Component\PhpStorage\PhpStorageInterface

鰏鲪鼷鼶龄鼩鼥龀麀鷱

\Drupal\Component\PhpStorage\FileStorage

鲬龬齛齗龯黱鼰鸏龀鰎鼜龣龢龮麲鵤鷛鼾黦黢鷯鷬鼰鸏龮鹣.htaccess鹟鼣鼶麮麬鴤鼴鰾鼫鵭鼈

\Drupal\Component\PhpStorage\FileStorage::htaccessLines()

\Drupal\Component\PhpStorage\MtimeProtectedFastFileStorage

龬齛齗龯黱鼰鸏龮鵡鵞鷢黳麀鷷鸨file_put_contents鴄齛齗鼣鼶龮鵱齳鴬齗麶鼣鼶麾

\Drupal\Component\PhpStorage\MtimeProtectedFileStorage

龬齛齗龯黱鼰鸏龮齳鵡鵞鷢黳麀齛齗鼣鼶

龸drupal鵺龀鸢鼥鼈

龇鵌鼣龀鰥鹰鵺龄鱠鹥鼷鼶龩龥鷜鷛默鰋龮鷔龰麥黬鳫鳧鴄龮龸drupal鵺齂鼿鼾鰇鰄鸳鼈

\Drupal\Core\PhpStorage\PhpStorageFactory::get($name);

鹥鰇鰄鰂鰀鸜鳃鼻鼹php龘龕龣龢鸃龮麲龩龥齂鼿龣龢鸃麾鯾龄龮鹳鹲默鰋龸鯼鼪鷜鷛鼣鼶鵺鯺鯶龮鷜鷛鼣鼶鵺鷜鷛默鰋鷔黵鰗鵹鼈

$settings['php_storage']['default']=[
    'class'=>"...", 
    'secret'=>"...", 
    'bin'=>"...", //储存bin,默认为本配置的第二级键名
    'directory'=>"..." //默认为PublicStream::basePath() . '/php';通常为/sites/default/files/php
];

鹳鵺'php_storage'鵼鷜鷛龳龮鹳黵鼻鲕鯴麾鹣default鹟龇龣龢鸃麾龮鵼鼻鼹龣龢鸃麾鯯鰏鷜鷛默鰋龮麲龩龥鳌鯭黷鵌默鼷龮鳴'default'齗鵼龣龢鸃龀麾鱋鯾龄龮'default'龬鯪鯩鯨鲪龮龘鯧鱆鱄鷜鷛龮鼠鼟鯦鼄鯺鯶龣龢鸃麾點黜龀鷜鷛龮鷔鳕鰠鯺鯶'default'鷜鷛龮鯢鱧龇鲬龬鳴鹉鼥鼠鼟鱆鱄鴆龮鱆鱄鴆鷔黵鼈

龣龢鸃鸳class鼈

鱆鱄鵼'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'龮龄黷鰾鰏鲪鹖鴂

鳫鳧secret鼈

鱆鱄鵼\Drupal\Core\Site\Settings::getHashSalt();

bin

bin 龘鯧龣龢鸃龸鲒鲐鼣鼶龰麥黵鹉鼥龀鹰龰麥麾龮鹥龣龢鸃鰗龬默鰋鯡龸鹥龰麥黵龮鱆鱄鹉鼥龣龢鸃麾龮鸽鴤龇鯟鯝鰇鰄麀鷱龀麾鱋鹁鳚龯鸽龇鷜鷛鷢鲌鲕鯴麾鸫龮鹥龳龄黷鹭鹪鯯鰏

php 龘龕龣龢龰麥directory鼈

龄黷龇麡齤龰麥龮鱆鱄鹉鼥鼈

\Drupal\Core\StreamWrapper\PublicStream::basePath() . '/php';

鯙鯙龇鼈sites/default/files/php

鳺鷔鼠鼟龣龢twig鯗鯖黩龀php鯔鯓鼣鼶龯龮龘龕鷔黵鼈

\Drupal\Core\PhpStorage\PhpStorageFactory::get ('twig');

鰔鰓鴧鼂鼈

1 龮bug鼈龸黷黵鯏鯌鰣鼕黙默鵺鴾鴻龬黢鲰鼈

\Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage::garbageCollection

鰣鼕龯麼鳴鹣.htaccess鹟鼣鼶鰸鰴龮齷鯋龑龎鸨鯇鼣鼶鼰龢龯齪鵤鷛鵼麲鱓鹁0444鷯鷬鸫龮鳗鳯鰸鰴齳鯆龮齛鯂麀鷱鷔黵鼈

龸@chmod ($directory, 0777);黩鸒鹒鵌鼈@chmod($fileinfo->getPathName(), 0777);龮

龸鰸鰴鮼鮹鵺鹒鯝鼈

if('.htaccess'==$fileinfo->getFilename ())

{ continue;}

鹥黢鲰鳗鳯鯗鯖黩龀鯔鯓龮鵖鵔龯齳齪鰾鴊鰣鼕

本书共88小节:

评论 (写第一个评论)