Ver Mensaje Individual
  #19 (permalink)  
Antiguo 21/11/2009, 20:54
Avatar de dannce4life
dannce4life
 
Fecha de Ingreso: junio-2008
Ubicación: localhost
Mensajes: 137
Antigüedad: 15 años, 10 meses
Puntos: 6
Respuesta: coger variable en cada pagina de la web

jonysi_d:

Voy a hacer un poco de docencia con vos para que te quede sabido.


Las variables $_SESSION, se pueden leer desde cualquier parte del sitio. Y SIEMPRE debe definirse la función session_start() antes de cualquier etiqueta HTML.

Con un ejemplo tal vez lo entiendas mejor:

Mi página principal:

Código:
<? session_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mi página Principal</title>

</head>

<body>
<? if(!$_POST): ?>
<form action="" method="post">
	<p>Introducí tu nombre</p>
	<input name="nombre" type="text" /><br />
	<input name="boton" type="submit" value="Enviar" />
</form>
<? else: ?>
	<? $_SESSION['nombre'] = $_POST['nombre']; ?>
	<p>Hola <?= $_SESSION['nombre'] ?>, Bienvenido al sitio</p>
<? endif; ?>
</body>
</html>
ahora mi página dos:
Código:
<? session_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mi página Principal</title>

</head>

<body>
<p>Hola <?= $_SESSION['nombre'] ?>, esta es la página número dos.</p>
</body>
</html>
espero estos ejemplos te sirvan para interpretar un poco mejor el lenguaje.
__________________
Gracias