logo
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
https://images.unsplash.com/photo-1516053256215-94022213b13c?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wzNjAzNTV8MHwxfHJhbmRvbXx8fHx8fHx8fDE3Mjg4NTY3ODR8&ixlib=rb-4.0.3&q=80&w=3230

Sesiones en PHP

Sesiones en PHP: Control total, seguridad garantizada durante toda la visita.

In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."

Creación y uso de sesiones

Primero deberemos crearla con la función session_start() 

 Guardar y recuperar datos

$_SESSION["loginUsuario"] = $_REQUEST["login"];

Session%

Función unset()

unset($_SESSION["loginUsuario"]);

Unset%

Función session_destroy()

$_SESSION = array(); session_destroy();

Destroy%
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."

Veamos un ejemplo

// Esto nos permitirá acceder al array $_SESSION
session_start();

// Comprobamos si llega un e-mail en la petición
if (isset($_REQUEST['email']))
{
    // Almacenamos el e-mail en una casilla del array $_SESSION,
    // con el nombre que queramos (por ejemplo, 'emailUsuario')
    $_SESSION['emailUsuario'] = $_REQUEST['email'];
}

// ... Resto del código de la página

https://cdn.wegic.ai/assets/onepage/img/f1a9e890-ba89-4d1b-b85f-375e88df4ccf.jpg?args=q%3A85%2Frs%3Afit%3A1072%3A804%2Fdpr%3A2%2Fsm%3A1
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."

Acceder a la variable

session_start();
if (isset($_SESSION['emailUsuario']))
{
    // Hacer lo que queramos con $_SESSION['emailUsuario']
}
else
{
    // Si no existe, podemos redirigir a otra página, por ejemplo
    header("Location:otraPagina.php");
}

https://cdn.wegic.ai/assets/onepage/img/fe71a9d3-d0b6-4127-a5bb-18368e096fb3.jpg?args=q%3A85%2Frs%3Afit%3A1072%3A804%2Fdpr%3A2%2Fsm%3A1
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."

Eliminar los datos

session_start();
if (isset($_SESSION['emailUsuario']))
    unset($_SESSION['emailUsuario']);
// También serviría esto:
// $_SESSION = array();
session_destroy();

https://cdn.wegic.ai/assets/onepage/img/9bce00ba-d671-4b1b-ab1e-4d5a1b710cfc.jpg?args=q%3A85%2Frs%3Afit%3A1072%3A804%2Fdpr%3A2%2Fsm%3A1
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."
In the right area, tell Kimmy what kind of section you want to add, like "I'd like to add a product introduction here."

© Cookies y Sesiones 2024, Todos los derechos reservados. Impulsando la creatividad e innovación en cada proyecto.