Ir para conteúdo

Pesquisar na Comunidade

Mostrando resultados para as tags ''fixed''.



Mais opções de pesquisa

  • Pesquisar por Tags

    Digite tags separadas por vírgulas
  • Pesquisar por Autor

Tipo de Conteúdo


Fóruns

  • A Cidade OTBR
    • OTServ Brasil
    • Atendimento
    • Taverna
  • Projetos Open Source
    • Canary
    • OTServBR-Global
    • Mehah OTClient
    • MyAAC
  • OpenTibia
    • Notícias e Discussões
    • Suporte - Dúvidas, Bugs, Erros
    • Downloads
    • Tutoriais
    • Show-Off
  • Outros
    • Design

Encontrado 1 registro

  1. [Znoteacc ] ERRO CACHE FIX

    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. É simples, eu corrigi o erro apenas retornando o cache dentro de uma variável e colocando o arquivo com tags PHP e quando é chamado o cache ele lê a variável. Caso o arquivo seja acessado pelo navegador não mostrará resultado algum. 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; } //$content = trim(@file_get_contents($this->_file)); include $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 code atual do arquivo engine/function/cache.phh por este code. Recomendo após alterar o arquivo deletar todo conteúdo da pasta cache antes de atualizar o site. Para os mais curiosos: Alterei: public function save() { $handle = fopen($this->_file, 'w'); fwrite($handle, $this->_content); fclose($handle); } Por: public function save() { $handle = fopen($this->_file, 'w'); $content = '<?php $cache =\''.$this->_content.'\' ?>'; fwrite($handle, $content); fclose($handle); } Aqui o arquivo quando for salvo o conteúdo é saldo dentro de uma variável e o arquivo é aberto e fechado com tags php. Antes: public function load() { if (!is_file($this->_file)) { return false; } ob_start(); include_once($this->_file); $content = ob_get_clean(); if (!isset($content) && strlen($content) == 0) { return false; } if ($content = json_decode($content, true)) { return (array) $content; } else { return $content; } } Por: public function load() { if (!is_file($this->_file)) { return false; } include $this->_file; if (!isset($cache) && strlen($cache) == 0) { return false; } if ($content = json_decode($cache, true)) { return (array) $content; } else { return $content; } } Aqui ele inclui o arquivo e pega o conteúdo da variável.
×