problema con cokies y setcookie
| From: | Igor Ormaetxebarria | Date: | Wed, 23 Mar 2005 12:18:49 +0000 |
| Subject: | problema con cokies y setcookie | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-53741@lists.php.net to get a copy of this message | ||
Hola lista,
estoy haciendo una web que usa sesiones y cookies, pero tengo problemas con las cookies.
he hecho una prueba tipo hola mundo con cookies, y en local me funciona bien, pero cuando lo subo al
servidor no funciona. Me podéis echar un cable? es un código sencillo de entender, creo.
Os paso el código y los links haber si podéis echarle un vistazo:
http://www.txurdi.net/pruebas/galletas2a/vergalleta.php
http://www.txurdi.net/pruebas/galletas2a/seteargalleta.php
http://www.txurdi.net/pruebas/galletas2a/borrargalleta.php
---------------------------------------------------------------------------------------------------------
vergalleta.php:
<?php
include_once ("funciones.php");
?>
<html>
<head>
<title>Pagina nueva 1</title>
</head>
<body>
<p>Lo que hay en la galleta:</p>
<pre>
<?php
$galletita_ser = $_COOKIE['prueba_galletas'];
$galletita = unserialize ($galletita_ser);
var_dump ($galletita);
?>
</pre>
</body>
</html>
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
seteargalleta.php:
<?php
include_once ("funciones.php");
$su_usuario_datos['id_usuario'] = 0;
$su_usuario_datos['nick'] = "txurdi";
$su_usuario_datos['pass'] = mktime();
$galletita_ser = serialize ($su_usuario_datos);
$tiempo = time() + 1209600;
setcookie ('prueba_galletas', $galletita_ser, $tiempo, "/", "");
?>
<html>
<head>
<title>Pagina nueva 1</title>
</head>
<body>
<p>Acabamos de setear la galleta, osea que no está cambiado.</p>
<p>Lo que hay en la galleta:</p>
<pre>
<?php
$galletita_ser = $_COOKIE['prueba_galletas'];
$galletita = unserialize ($galletita_ser);
var_dump ($galletita);
?>
</pre>
</body>
</html>
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
borrargalleta.php:
<?php
include_once ("funciones.php");
borrar_galleta();
?>
<html>
<head>
<title>Pagina nueva 1</title>
</head>
<body>
<p>Lo que hay en la galleta:</p>
<pre>
<?php
$galletita_ser = $_COOKIE['prueba_galletas'];
$galletita = unserialize ($galletita_ser);
var_dump ($galletita);
?>
</pre>
</body>
</html>
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
funciones.php:
<?php
define('SU_GALLETA','prueba_galletas');
define('TIEMPO_GALLETA', 1209600); //14 dias. 14*24*60*60
function existe_galleta()
{
if (isset($_COOKIE[SU_GALLETA])) return true;
else return false;
}
function cargar_galleta()
{
$galletita_ser = $_COOKIE[SU_GALLETA];
$galletita = unserialize ($galletita_ser);
// $galletita2 = unserialize ($galletita);
return $galletita;
}
function guardar_galleta($su_usuario_datos)
{
$galletita_ser = serialize ($su_usuario_datos);
$tiempo = time() + TIEMPO_GALLETA;
setcookie (SU_GALLETA, $galletita_ser, $tiempo, '/', '');
}
function borrar_galleta()
{
setcookie (SU_GALLETA, "", 0, '/', '');
}
?>
---------------------------------------------------------------------------------------------------------