Extralight browser-webserver communication via cookies (+) [message #172662] |
Thu, 24 February 2011 03:22 |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
It could replace 97% of all xmlhttprequest stuff. Tested in IE and FF.
Below just a minimalistic example of the whole idea.
====================================================
<?php // me.php
if (array_key_exists('sel', $_COOKIE) && $_COOKIE['sel']) {
setcookie('sel', 'You_chose_'.$_COOKIE['sel'].'!', 0);
header('HTTP/1.1 204'); // <- note this...
exit(); // and this. The me.php is loaded only *ONCE*;
}
?>
<html>
<head>
<script>
var dT;
var prev_cookie;
function receiver() {
if (document.cookie == prev_cookie)
return;
clearInterval(dT);
document.myform.txtArea.value = unescape(document.cookie);
}
function sender() {
document.cookie = "sel=" + document.getElementById("sel").value;
prev_cookie = document.cookie;
window.location.href = "me.php";
dT = setInterval(receiver, 100);
}
function reset_cookie() {
document.cookie = "sel=";
}
</script>
</head>
<body>
<br><br>
<center>
<form name="myform">
<label><?php echo date(DATE_RFC822); ?></label>
<br><br>
<textarea name="txtArea" cols="30" rows="8"></textarea>
<br><br>
<select id="sel" style="width:200px;" onchange="sender();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br><br>
<input type="button" value="reset_cookie();"
onclick="reset_cookie();" />
</form>
</center>
</body>
</html>
=====================================================
|
|
|
|
|
Re: Extralight browser-webserver communication via cookies (+) [message #172671 is a reply to message #172662] |
Thu, 24 February 2011 13:37 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
.oO(n00m)
> It could replace 97% of all xmlhttprequest stuff.
Not really. Where's this number coming from?
> Tested in IE and FF.
> Below just a minimalistic example of the whole idea.
I consider it nonsense. It makes web applications even more unreliable
and doesn't save anything. Whether you put your content in a misused
cookie or in the message body doesn't make much of a difference.
> ====================================================
> <?php // me.php
> if (array_key_exists('sel', $_COOKIE) && $_COOKIE['sel']) {
> setcookie('sel', 'You_chose_'.$_COOKIE['sel'].'!', 0);
> header('HTTP/1.1 204'); // <- note this...
> exit(); // and this. The me.php is loaded only *ONCE*;
Loaded where? In the browser? This would also be the case with a regular
XHR call - one time the whole document and then only short fragments.
And for the server the load is also the same.
Micha
|
|
|
|
Re: Extralight browser-webserver communication via cookies (+) [message #172673 is a reply to message #172662] |
Thu, 24 February 2011 14:22 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
n00m wrote:
> It could replace 97% of all xmlhttprequest stuff. Tested in IE and FF.
> Below just a minimalistic example of the whole idea.
Cookies
- can be disabled, or configured so that each cookie (per site or session)
must be confirmed;
- are limited in size (IE default¹: 4096 bytes)
- are limited in numbers (IE default: 300)
- are limited per unique host or domain name (IE default: 20)
___
¹ These defaults are recommendations from RFC 2109, see
<http://support.microsoft.com/kb/306070/en-us>
You also forgot researching about HTML5's localStorage and sessionStorage,
which are not as limited as are cookies.
Your minimalistic example is not even Unicode-safe, let alone Valid. It
would appear to be best if you learned the basics first (and got yourself a
real name).
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
|
|
|
|
Re: Extralight browser-webserver communication via cookies (+) [message #172675 is a reply to message #172673] |
Thu, 24 February 2011 14:48 |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
On Feb 24, 4:22 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> Cookies
>
> - can be disabled, or configured so that each cookie (per site or session)
> must be confirmed;
> ...
xmlhttprequest can be lost or disabled or missing;
Also it can happen the power failure;
Your PC can be stolen;
Aha?
= Life is complex: it has both real and imaginary parts. =
|
|
|
Re: Extralight browser-webserver communication via cookies (+) [message #172676 is a reply to message #172675] |
Thu, 24 February 2011 15:38 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
n00m wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Cookies
>>
>> - can be disabled, or configured so that each cookie (per site or
>> session) must be confirmed;
>> ...
>
> xmlhttprequest can be lost
Lost?
> or disabled
I do not know of any browser where you can disable XHR but not disable
client-side script support in turn. The latter would be required for your
suggestion to be a viable replacement.
> or missing;
Yes, although no such commonly browser that could set cookies with scripting
comes to my mind.
> Also it can happen the power failure;
> Your PC can be stolen;
>
> Aha?
> = Life is complex: it has both real and imaginary parts. =
Reductio ad ridiculum, but perhaps I should not be too much surprised.
And since you did not rebut my other points, I think you are out of
arguments.
As it stands, your suggestion could serve as yet another fallback, but it
can never replace "97% of all XHR".
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
|
|
|
|
|