Javascript-форум (https://javascript.ru/forum/)
-   Internet Explorer (https://javascript.ru/forum/css-html-internet-explorer/)
-   -   Динамическая установка Cookies (https://javascript.ru/forum/css-html-internet-explorer/5309-dinamicheskaya-ustanovka-cookies.html)

Paguo-86PK 03.10.2009 19:46

Динамическая установка Cookies
 
Решил в замен JShttpRequest попробовать динамически передавать данные через кукисы :write:
<?PHP
$text = array("Line_#1:", "Line_#2:", "Line_#3:");
if(isset($_GET["file"])) {
 $f = $_GET["file"] * 1;
 setcookie("data", ($f < count($text) ? ($text[$f]) : ""), time()+3600);
?><html><head></head><body><?echo $f?></body><?
} else {?>
<html><head><title>PHP + cookies</title><script>
var
 Phase = 0;
function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function Reader() {
 window.status = Phase;
 data = getCookie("data");
 if(data != null) {
  document.getElementById("Log").innerHTML += data + "<br/>";
  setCookie("data", "");
  document.getElementById("file").location.replace("cook.php?file=" + (++ Phase));
 }
}
</script></head>
<body>
<iframe id="file" onload="setTimeout('Reader()',1)" src="cook.php?file=0" style=display:none></iframe>
<pre id="Log"><hr/></pre><hr/>
</body></html>
<?}
?>
Но что-то не совсем то, что ожидал... :blink:
В Opera ещё более-менее, а в IE - :-?


Часовой пояс GMT +3, время: 14:20.