Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/03/2004, 16:11
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 7 meses
Puntos: 45
cookies facilmente

Nose, me ha venido hoy la "luz" y la inspiracion , no he estado pensando para sacar el sistema, solo se me ha ocurrido.

Cómo poner una cookie y borrarla en tiempo de ejecucion es sencillo. Fijate en este script, le he puesto una interfaz de prueba:

Código PHP:
<script language="javascript">
<!--
//  Cookie Functions -- "Toss Your Cookies" Version (22-Mar-96)
//  Autor:  Bill Dortch, hIdaho Design <[email protected]>
//  Traductor: Carlos Castillo <[email protected]>
//  URL Ref: http://www.hIdaho.com/,http://www.dic.uchile.cl/~manual/

function FixCookieDate (date) {
  var 
base = new Date(0);
  var 
skew base.getTime(); // dawn of (Unix) time - should be 0
  
if (skew 0)  // Except on the Mac - ahead of its time
    
date.setTime (date.getTime() - skew);
}

// Funcion interna que retorna el valor desempaquetado de una cookie.
function getCookieVal (offset) {
  var 
endstr document.cookie.indexOf (";"offset);
  if (
endstr == -1)
    
endstr document.cookie.length;
  return 
unescape(document.cookie.substring(offsetendstr));
}

function 
GetCookie (name) {
  var 
arg name "=";
  var 
alen arg.length;
  var 
clen document.cookie.length;
  var 
0;
  while (
clen) {
    var 
alen;
    if (
document.cookie.substring(ij) == arg)
      return 
getCookieVal(j);
    
document.cookie.indexOf(" "i) + 1;
    if (
== 0) break; 
  }
  return 
null;
}
// argumentos: name,value,[expires],[path],[domain],[secure]
function SetCookie (namevalue) {
  var 
argv SetCookie.arguments;
  var 
argc SetCookie.arguments.length;
  var 
expires = (argc 2) ? argv[2] : null;
  var 
path = (argc 3) ? argv[3] : null;
  var 
domain = (argc 4) ? argv[4] : null;
  var 
secure = (argc 5) ? argv[5] : false;
  if (
expires!=nullFixCookieDate(expires);         // para correccion automatica de fecha.
  
document.cookie name "=" escape (value) +
    ((
expires == null) ? "" : ("; expires=" expires.toGMTString())) +
    ((
path == null) ? "" : ("; path=" path)) +
    ((
domain == null) ? "" : ("; domain=" domain)) +
    ((
secure == true) ? "; secure" "");
}

function 
DeleteCookie (name) {
  var 
exp = new Date();
  
FixCookieDate (exp); // Correct for Mac bug
  
exp.setTime (exp.getTime() - 1);  // This cookie is history
  
var cval GetCookie (name);
  if (
cval != null)
    
document.cookie name "=" cval "; expires=" exp.toGMTString();
}


//-->
</script>

Nombre <input type="text" name="nombre" size="30"><br>
Valor <input type="text" name="valor" size="62"><br>
<input type="button" value="creaCookie" onclick="SetCookie(nombre.value,valor.value)"><br>
<input type="button" value="valorCookie" onclick="resultado.value=GetCookie(nombre.value)"><br>
Resultado <input type="text" name="resultado" size="62"><br>
<input type="button" value="borraCookie" onclick="DeleteCookie(nombre.value)"> 

Si resulta bien el sistema sin fallos mas o menos intentare publicarlo con el codigo entero.

Un saludo.
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.

Última edición por derkenuke; 04/03/2004 a las 16:17