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(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
// argumentos: name,value,[expires],[path],[domain],[secure]
function SetCookie (name, value) {
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!=null) FixCookieDate(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.