Foros del Web » Programando para Internet » PHP »

problema con manejo de sessiones

Estas en el tema de problema con manejo de sessiones en el foro de PHP en Foros del Web. hola como andan... estoy tratando de utilizar sesiones pero no logro hacer q funcione... Uso el paquete Xampp q instala el php, apache, etc... En ...
  #1 (permalink)  
Antiguo 17/03/2005, 16:59
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
problema con manejo de sessiones

hola como andan...
estoy tratando de utilizar sesiones pero no logro hacer q funcione...
Uso el paquete Xampp q instala el php, apache, etc...

En fin...

tengo una pag1.php q me crea la sesion y todas las variables de sesion q necesito... en esta tengo un link q me va a pag2.php y esta en vez de tomarme la sesion creada anteriormente me crea una nueva... y no deberia ser asi...

este es el codigo de las pag

//pag1.php
<?php
session_start();
$SESSION["usuario"] = "fede";
echo "$SESSION[usuario] <br>";
echo "<a href='otro2.php'>link</a>";
?>

//pag2.php
<?php
session_start();
if(isset($SESSION["usuario"])){
echo "$SESSION[usuario]";
}else{
echo "no hay session";
}
?>


con este codigo... al entrar a pag1.php imprim "fede"... y esta bien... cuando hago click en el enlace me va a pag2.php y me muestra "no hay session".... como puede ser posible???.....
yo kiero mantener la session mientras el usuario este....

me pidieron hacer esto sin usar cookies....

muchas gracias

salu2
=P
  #2 (permalink)  
Antiguo 17/03/2005, 17:06
 
Fecha de Ingreso: mayo-2004
Ubicación: Managua, Nicaragua
Mensajes: 281
Antigüedad: 19 años, 11 meses
Puntos: 0
Creo que es $_SESSION["usuario"]
__________________
Julio Hernández
  #3 (permalink)  
Antiguo 17/03/2005, 17:31
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
sisis me comi el _ cuando pase aca el codigo....

sige sin funcionar

gracias

Última edición por fed_loco; 17/03/2005 a las 17:32
  #4 (permalink)  
Antiguo 17/03/2005, 17:34
 
Fecha de Ingreso: mayo-2004
Ubicación: Managua, Nicaragua
Mensajes: 281
Antigüedad: 19 años, 11 meses
Puntos: 0
Pero en el link está 'otro2.php' y no pag2.php
__________________
Julio Hernández
  #5 (permalink)  
Antiguo 17/03/2005, 17:42
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
Perdon... anteriormente escribi todo rapido y me comi letras... este es el codigo q uso y no anda... la pag 2 me crea una sesion nueva... lo verifique usando session_id()... y no me mantiene la sesion anteriormente creada...

//pag1.php
<?php
session_start();
$_SESSION["usuario"] = "fede";
echo "$_SESSION[usuario] <br>";
echo "<a href='pag2.php'>link</a>";
?>

//pag2.php
<?php
session_start();
if(isset($_SESSION["usuario"])){
echo "$_SESSION[usuario]";
}else{
echo "no hay session";
}
?>


gracias
  #6 (permalink)  
Antiguo 17/03/2005, 17:54
Avatar de Seppo  
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
lo que me parece es q las variables aparecen entre comillas, entonces las devuelve tal cual
probá lo siguiente

//pag1.php
<?php
session_start();
$SESSION["usuario"] = "fede";
echo $SESSION[usuario]."<br>";
echo "<a href='otro2.php'>link</a>";
?>

//pag2.php
<?php
session_start();
if(isset($SESSION["usuario"])){
echo $SESSION[usuario];
}else{
echo "no hay session";
}
?>
  #7 (permalink)  
Antiguo 17/03/2005, 18:12
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
no funciona...
utilizando session_id() en ambas pagina pude observar q son sesiones distintas...

cuando entra a la pag1.php me crea la session A y al ir a la pag2.php me crea la session B y no me mantiene la session creada A....

creo q ese es el problema pero no puedo solucionarlo
  #8 (permalink)  
Antiguo 18/03/2005, 08:17
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Cita:
utilizando session_id() en ambas pagina pude observar q son sesiones distintas...
Si eso te sucede .. entonces tienes problemas en la propagación del SID. .. NO sé en tu configuración de PHP como lo haces .. pero lo que es en el ejemplo de código planteado "asumes" que PHP lo tiene que hacer automáticamente por:

URL:
session.use_trasn_sid = ON

o por Cookies:
session.use_cookies = ON

en este último caso necesitas de un navegador que -acepte- dichas cookies. Y que ningún otro dispositivo o nivel de seguridad de un navegador, proxy o similar esté bloqueando esa cookie.

Puedes ver tu configuración de PHP (y esas directivas) en un phpinfo() o bien en tu php.ini

más info:
www.php.net/session
(busca por el término "SID": Identificador Único de Sesión y lo referente a su propagación).

Un saludo,

PD: no muestras como usastes session_id() .. pero debería ser bajo tu session_Start() .. revisa eso también.
  #9 (permalink)  
Antiguo 18/03/2005, 14:18
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
sisi... kiero q lo haga automaticamente

probe lo q me digiste pero no logre hacerlo funcionar... =(

aca pongo como ta configurado mi php.... use le paquete XAMPP q te instala el apache, php y mysql.....



/**************************/
[Session]
; Handler used to store/retrieve data.
session.save_handler = files

; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path= c:\apachefriends\xampp\tmp

; Whether to use cookies.
session.use_cookies = 1

; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1

; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = /

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php

; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_dividend,
; e.g. 1/100 means 1%.

session.gc_probability = 1
session.gc_dividend = 1000

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning seperately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.

session.bug_compat_42 = 0
session.bug_compat_warn = 1

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public,} to determine HTTP caching aspects.
; or leave this empty to avoid sending anti-caching headers.
session.cache_limiter = nocache

; Document expires after n minutes.
session.cache_expire = 180

; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = On

; The URL rewriter will look for URLs in a defined set of HTML tags.
; form/fieldset are special; if you include them here, the rewriter will
; add a hidden <input> field with the info which is otherwise appended
; to URLs. If you want XHTML conformity, remove the form entry.
; Note that all valid entries require a "=", even if no value follows.
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeent ry"

; Select a hash function
; 0: MD5 (128 bits)
; 1: SHA-1 (160 bits)
session.hash_function = 0

; Define how many bits are stored in each character when converting
; the binary hash data to something readable.
;
; 4 bits: 0-9, a-f
; 5 bits: 0-9, a-v
; 6 bits: 0-9, a-z, A-Z, "-", ","
session.hash_bits_per_character = 4

; The URL rewriter will look for URLs in a defined set of HTML tags.
; form/fieldset are special; if you include them here, the rewriter will
; add a hidden <input> field with the info which is otherwise appended
; to URLs. If you want XHTML conformity, remove the form entry.
; Note that all valid entries require a "=", even if no value follows.
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fields et="

/******************************/


gracias
  #10 (permalink)  
Antiguo 18/03/2005, 15:11
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Esto ya hace que tu SID se propague en cookies ..
session.use_cookies = 1

Si modificastes tu php.ini .. recuerda reiniciar tu servidor HTTP y de comprobar los cambios haciendo un phinfo();

Revisa tu navegador como tienes el tema de aceptación de cookies (si es necesario modifica momentánemanete los niveles de seguridad de tu navegador si los usas) .. No sé si usas algún antivirus o firewall .. pero revisa que estos no estén bloqueando esas cookies.

Un saludo,
  #11 (permalink)  
Antiguo 18/03/2005, 16:00
 
Fecha de Ingreso: julio-2004
Mensajes: 61
Antigüedad: 19 años, 8 meses
Puntos: 0
muchisimas gracias!

era el firewall q el q no me daba problemas!!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:14.