Bem interessante, aguardando mais comentarios sobre seu conteudo!
- Fórum
- OTServ
- Tutoriais
- Tutoriais de Websites
- [ZnoteACC] Corrigindo BUG Cache
JB
[ZnoteACC] Corrigindo BUG Cache
Por jb2, 09 de fev. de 2013 em Tutoriais de Websites
znoteacc
bug
corrigir
2
1.4k
info
Grupo: Herói
Registrado: 23/12/08
Posts: 2.4k
Reputação: +359
Gênero: Masculino
Char no Tibia: Gordo Warlike

09 de fevereiro de 2013 às 08:00

info
Grupo: Campones
Registrado: 26/12/12
Posts: 99
Reputação: +28
Estava estudando a estrutura do OOP do website znoteacc e verifiquei que é possível visualizar os arquivos de cache pelo browser, até ai tudo bem, mas caso o usuário deseje usar o sistema de cache para algum sistema que contém configurações do banco de dados e deseja indexar as configurações via cache o arquivo poderá ser visto pelo browser, e assim, as configuração dele estariam exposta.
Não é preciso fazer essa alteração, mas caso deseja ter maior nível de segurança em sua aplicação, recomendo fazer.
O Code:
<?php class Cache { protected $_file = false; protected $_lifespan = 0; protected $_content; const EXT = '.cache.php'; /** * @param string $file * @access public * @return void **/ public function __construct($file) { $this->_file = $file . self::EXT; $this->setExpiration(config('cache_lifespan')); } /** * Sets the cache expiration limit (IMPORTANT NOTE: seconds, NOT ms!). * * @param integer $span * @access public * @return void **/ public function setExpiration($span) { $this->_lifespan = $span; } /** * Set the content you'd like to cache. * * @param mixed $content * @access public * @return void **/ public function setContent($content) { switch (strtolower(gettype($content))) { case 'array': $this->_content = json_encode($content); break; default: $this->_content = $content; break; } } /** * Validates whether it is time to refresh the cache data or not. * * @access public * @return boolean **/ public function hasExpired() { if (is_file($this->_file) && time() < filemtime($this->_file) + $this->_lifespan) { return false; } return true; } /** * Returns remaining time before scoreboard will update itself. * * @access public * @return integer **/ public function remainingTime() { $remaining = 0; if (!$this->hasExpired()) { $remaining = (filemtime($this->_file) + $this->_lifespan) - time(); } return $remaining; } /** * Saves the content into its appropriate cache file. * * @access public * @return void **/ public function save() { $handle = fopen($this->_file, 'w'); $content = '<?php $cache =\''.$this->_content.'\' ?>'; fwrite($handle, $content); fclose($handle); } /** * Loads the content from a specified cache file. * * @access public * @return mixed **/ public function load() { if (!is_file($this->_file)) { return false; } include_once $this->_file; if (!isset($cache) && strlen($cache) == 0) { return false; } if ($content = json_decode($cache, true)) { return (array) $content; } else { return $content; } } }Só alterar o conteúdo atual do arquivo engine/function/cache.php por este code.
Recomendo após alterar o arquivo deletar todo conteúdo da pasta cache antes de atualizar o site.