<?php
/* Установка кодироок в UTF-8 */
mb_internal_encoding("UTF-8"); // установим внутреннюю кодировку скрипта
mb_http_output( "UTF-8" ); // устанавливаем кодировку для http-вывода
//settings
$cache_ext = '.html'; //file extension
$cache_time = 1800; //Cache file expires after these seconds (1 hour = 3600 sec) (8 hour = 28800 sec) (12 hour = 43200 sec)
$cache_folder = 'cache/'; //folder to store Cache files
$ignore_pages = array('', '');
$dynamic_url = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING']; // requested dynamic page (full url)
$cache_file = $cache_folder.md5($dynamic_url).$cache_ext; // construct a cache file
$ignore = (in_array($dynamic_url,$ignore_pages))?true:false; //check if url is in ignore list
if (!$ignore && file_exists($cache_file) && time() - $cache_time < filemtime($cache_file)) { //check Cache exist and it's not expired.
ob_start('ob_gzhandler'); //Turn on output buffering, "ob_gzhandler" for the compressed page with gzip.
readfile($cache_file); //read Cache file
echo '<!-- cached page - '.date('l jS \of F Y h:i:s A', filemtime($cache_file)).', Page : '.$dynamic_url.' -->';
ob_end_flush(); //Flush and turn off output buffering
exit(); //no need to proceed further, exit the flow.
}
//Turn on output buffering with gzip compression.
ob_start('ob_gzhandler');
$_SERVER['post_cache'] = $post;
if (!is_dir($cache_folder)) { //create a new folder if we need to
mkdir($cache_folder);
}
if(!$ignore){
$fp = fopen($cache_file, 'w'); //open file for writing
fwrite($fp, ob_get_contents()); //write contents of the output buffer in Cache file
fclose($fp); //Close file pointer
}
ob_end_flush(); //Flush and turn off output buffering
?>
<?php
class DataBase {
private $file;
private $data = [];
function __construct($file)
{
$this->file = $file;
$this->data = (array) @json_decode(file_get_contents($file), true);
}
public function add($id, $item)
{
if(isset($this->data[$id])) {
return false;
}
$this->data = [$id => $item] + $this->data;
return true;
}
public function find($id)
{
if(!isset($this->data[$id])) {
return false;
}
return $this->data[$id];
}
public function remove($id)
{
if(!isset($this->data[$id])) {
return false;
}
unset($this->data[$id]);
return true;
}
public function replace($id, $item)
{
if(!isset($this->data[$id])) {
return false;
}
$this->data[$id] = $item;
return true;
}
public function save()
{
return file_put_contents($this->file, json_encode($this->data));
}
public function all()
{
return $this->data;
}
}
?><?php
header('HTTP/1.0 404 Not Found');
?>
//$isWinCharset = mb_check_encoding($postResult, "windows-1251");
//if ($isWinCharset) {
// $postResult = iconv("windows-1251", "UTF-8", $postResult);
//}
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" >
и менять ее на ?//$isWinCharset = mb_check_encoding($postResult, "windows-1251");
//if ($isWinCharset) {
// $postResult = iconv("windows-1251", "UTF-8", $postResult);
//}
<?php
$ch = curl_init();
$user_agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $engine_url );
//"identity", "deflate" , "gzip"
//curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$tmpResult = curl_exec($ch);
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
curl_close($ch);
$tmpHeaders = substr($tmpResult, 0, $header_size);
$postResult = substr($tmpResult, $header_size);
$headers = array();
foreach(explode("\n",$tmpHeaders) as $header)
{
$tmp = explode(":",trim($header),2);
if (count($tmp)>1)
{
$headers[strtolower($tmp[0])] = trim(strtolower($tmp[1]));
}
}
$encoding="utf-8"; //default
if (isset($headers['content-type']))
{
$tmp = explode("=", $headers['content-type']);
if (count($tmp)>1) $encoding = $tmp[1];
}
if ($encoding != "utf-8") $postResult = iconv($encoding, "UTF-8", $postResult);
//$isWinCharset = mb_check_encoding($postResult, "windows-1251");
//if ($isWinCharset) {
// $postResult = iconv("windows-1251", "UTF-8", $postResult);
//}
echo $postResult;
?><?php
header('HTTP/1.0 404 Not Found');
?>
$isWinCharset = mb_check_encoding($postResult, "windows-1251");
if ($isWinCharset) {
$postResult = iconv("windows-1251", "UTF-8", $postResult);
}
encoding='utf-8' # кодировка по умолчанию
tmp = r.headers.get('Content-Type').split('=') #режем по =, что справа - кодировка
if len(tmp)>1: #если кодировка в заголовке есть - будет 2 элемента
encoding=tmp[-1] # тогда берём последний
page = r.content.decode(encoding)
$ch = curl_init();
$user_agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $engine_url );
//"identity", "deflate" , "gzip"
//curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$postResult = curl_exec($ch);
curl_close($ch);
$isWinCharset = mb_check_encoding($postResult, "windows-1251");
if ($isWinCharset) {
$postResult = iconv("windows-1251", "UTF-8", $postResult);
}
echo $postResult;