image


Valora:  4/5
Inicio » PHP » PHP Tutorial » Sessions




Log on session

By: Jose Valle

In order to use sessions in PHP, you must log on first. We can do this by actually using the statement session_start(), or by recording a variable in one session using session_register('myVariable'). In both cases a new session is created if there is no session, or the current session is retaken. See a simple example:

<?php // Manual de PHP de WebEstilo.com

session_start();
echo "He inicializado la sesión";
?>




Execute View code

This is the most basic form, if the user has enabled cookies, PHP will automatically insert the session and this will be run from one page to another without any further action. From a practical point of view, the session is operational but we do not see anything. We can get the session at any moment by using the statement session_id(). Insert the following row in the subsequent pages to see if the session is available:

<?php // Manual de PHP de WebEstilo.com

session_start();
echo 'La sesión actual es: '.session_id();
?>



Execute View code

In this case session_start() proves in the cookies that there is a session and continues with it, session_id() returns the current identifier.





WebEstilo.com - Introduzca su e-mail y conozca las novedades. No hacemos Spam.
Google
  Web WebEstilo.com   
 
Valid HTML 4.01!
Última modificación:25 de Diciembre de 2004. Spain - España.
© 1998-2004 por Joaquin Gracia. Todos los derechos reservados.