Implement a session system to protect my php files, I include it in every php file that shows a menu.
<?php
// CONECTANDO AL SISTEMA SEGUN TIPO DE USUARIO//
if (isset($_SESSION['conectado']) && $_SESSION['conectado'] == true && $_SESSION['nivel']==0) {
// ------------------------ //
} else {
// MENSAJE DE ACCESO NEGADO //
echo ('<script>alert("No tiene permisos suficientes para acceder a esta parte del sistema");</script>');
echo ("<script>window.location = 'index.php';</script>");
exit;
// ------------------------ //
}
// ------------------------ //
$now = time();
if($now > $_SESSION['expira']) {
//DESTRUYO LA SESION, ANTES DE SACARLO DEL SISTEMA//
session_destroy();
// MENSAJE DE SESIÓN EXPIRADA //
echo ('<script>alert("Su sesión ha expirado");</script>');
echo ("<script>window.location = 'index.php';</script>");
exit;
}
// ------------------------ //
?>
It happens that I also have another type of file called actions, these are all the actions that execute the php: insert, modify, delete, consult to prevent people from entering them add:
if(!isset($_POST['submit'])){
}
echo ('<script>alert("No tiene permisos suficientes para acceder a esta parte del sistema");</script>');
echo ("<script>window.location = 'index.php';</script>");
exit;
and finally I have FUNCTIONS, which are responsible for filling selects, checkbox, one that another function that shows the user data and functions that are activated with $ .post of JSON.
The problem is that I do not know how to protect these files and the person could access them (although not all of them show important information)
* If I use the ISSET method they give me an error because there is no submit and it does not include them in the system.
* If I include the session's method, it gives me an error because I must start the session before, I write the session_start and it tells me that they have already sent the header (before in the menu where this file is included of function
What can I do to avoid access to these files?