<?php
|
|
|
|
session_start();
|
|
|
|
if (empty($_SESSION['csrf'])) {
|
|
if (function_exists('random_bytes')) {
|
|
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
|
} else if (function_exists('mcrypt_create_iv')) {
|
|
$_SESSION['csrf'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
|
|
} else {
|
|
$_SESSION['csrf'] = bin2hex(openssl_random_pseudo_bytes(32));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Escapes HTML for output
|
|
*
|
|
*/
|
|
|
|
function escape($html) {
|
|
return htmlspecialchars($html, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
|
|
}
|
|
|
|
/**
|
|
* Función para escribir logs
|
|
*/
|
|
|
|
function escribe_log($log_msg)
|
|
{
|
|
$log_dir = $_SERVER['DOCUMENT_ROOT'] ."/gestionrepostajes/log";
|
|
if (!file_exists($log_dir))
|
|
{
|
|
// create directory/folder uploads.
|
|
mkdir($log_dir, 0777, true);
|
|
}
|
|
$log_file_data = $log_dir.'/log_' . date('Y-M-d') . '.log';
|
|
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
|
|
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
|
|
}
|