How to use Cookies in Internet Explorer?

Asked

Viewed 275 times

0

I am trying to store cookies for an application I developed in PHP and noticed that in Internet Explorer my cookies are not being stored (or are expiring soon after its creation). In my code I set Cookies this way:

setcookie("login", $login_confirmacao, time() + 3600, "/");
setcookie("senha", $senha_confirmacao, time() + 3600, "/");

I noticed that when disabling this function the browser stored Cookies:

[ ] Block cookies from third parties who do not have a compact privacy policy.

How do I set this "Compact Privacy Policy" ? or how do I use cookies in IE?

3 answers

2

If you want to handle cookies in IE with Javascript, a good approach would be to use lib: Jquerycookie

The use itself is quite simple:

Store: $.cookie('variavel_nome', 'valor');

Read: $.cookie('variavel_nome');

Delete: $.removeCookie('variavel_nome');

1


IE does not trust cookies from iframes that have no privacy policy (p3p).

Then you would have to make an XML file that identifies your privacy policy. That would be the compact version. To do it right you would have to create a full version too, but the only reference I found are for paid generators.

Reference: http://www.w3.org/P3P/details.html

Example:

<META>
  <POLICY-REFERENCES>
    <POLICY-REF about="/url-da-politica-de-privacidade/p3p.xml">
      <INCLUDE>/</INCLUDE>
      <COOKIE-INCLUDE/>
    </POLICY-REF>
  </POLICY-REFERENCES>
</META>

Within the INCLUDE tag you put which parts of your site this privacy policy cover in the "/" case is all.

Then, in PHP you would have to put the headers according to your privacy policy, if you are just testing you can only use the headers, but if you are going to put in production you should do the other steps:

Example:

header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');

Each of these acronyms represents a type of behavior regarding user privacy on the part of your website.

A complete list: http://www.p3pwriter.com/LRN_111.asp

0

I don’t understand your question but if you have any desire to add one cookie, that should work:

<script language="JavaScript">
<!--
letterTable='ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm';
function rot13(str) {
 var outStr='';
 for (var k=0;k<str.length;k++) {
  var ch=str.charAt(k);
  var ix=letterTable.indexOf(ch);
  outStr+= (ix==-1) ? ch : letterTable.charAt(ix+13) ;
 }
 return outStr;
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
//-->
</script>

<pre>
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
</pre>

Form:

<form name="setCookie">
<table border=0 cellpadding=3 cellspacing=3>
<tr><td>Nome do Cookie:&nbsp;
</td><td><input name=t1 type=text size=20 value="NomeDocookie">
</td></tr>
<tr><td>Valor do Cookie:&nbsp;
</td><td><input name=t2 type=text size=20 value="Valor Do Cookie">
</td></tr>
<tr><td>Deve expirar em:&nbsp;
</td><td><input name=t3 type=text size=3 value="5"> Dias de hoje
</td></tr>
<tr><td></td><td><input name=b1 type=button value="Set Cookie"
onClick="SetCookie('__Teste__',rot13(this.form.t1.value,this.form.t3.value));
SetCookie(this.form.t1.value,this.form.t2.value,this.form.t3.value);">
</td></tr></table>
</form>
  • Legal. It is valid to use the answer also to ask for more information from the author, if you are willing to edit it later to update with the additional information. But soon you will be able to comment too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.