Skip to content

Instantly share code, notes, and snippets.

@rafaduran
Created August 21, 2012 09:59
Show Gist options
  • Save rafaduran/3414122 to your computer and use it in GitHub Desktop.
Save rafaduran/3414122 to your computer and use it in GitHub Desktop.
IFrame Cookies
<?php
header('P3P: CP=HONK');
setcookie('test_cookie', '1', 0, '/');
?>
<div id="test_cookie" style="position: absolute; top: -10000px"></div>
<script>
window.setTimeout(function() {
if (document.cookie.indexOf('test_cookie=1') < 0) {
var
name = 'test_cookie',
div = document.getElementById(name),
iframe = document.createElement('iframe'),
form = document.createElement('form');
iframe.name = name;
iframe.src = 'javascript:false';
div.appendChild(iframe);
form.action = location.toString();
form.method = 'POST';
form.target = name;
div.appendChild(form);
form.submit();
}
}, 10);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment