FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Extralight browser-webserver communication via cookies (+)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Extralight browser-webserver communication via cookies (+) [message #172662] Thu, 24 February 2011 03:22 Go to previous message
n00m is currently offline  n00m
Messages: 25
Registered: February 2011
Karma:
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>
=====================================================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Proxy to open blocked sites
Next Topic: terminate a PHP script
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 01:13:28 GMT 2024

Total time taken to generate the page: 0.03514 seconds