Hola,
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.
He hecho una página que escribe unos datos en la cookie, y otra que los lee. Si entro en la que escribe y luego en la que lee, en local aparece el contenido de la cookie, pero en cuando la subo, ya no. Podéis probarlo con los links de abajo.
Me podéis echar un cable? es un código sencillo de entender, creo.
gracias de antemano.
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/gallet...eargalleta.php http://www.txurdi.net/pruebas/gallet...rargalleta.php
---------------------------------------------------------------------------------------------------------
vergalleta.php:
Código:
<?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:
Código:
<?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:
Código:
<?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:
Código:
<?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, '/', '');
}
?>