How to set third-party cookies with iframe

How to set third-party cookies with iframe?

I had problem with the lead base ad click tracking. I was using the iFrame to track the lead information from the advertiser site. But somehow IE is not sending any cookie information from there. Infect firefox also doesn’t send any cookie information for the first request (i.e. when the iFrame src page is called) but if you call any page from the main file (i.e. specified in the source for iFrame like image or script src), I get the cookies.

What are third-party cookies?

If you put your code on other website using iFrame which calls pages from your site, then the cookies groups are called third party cookies (as both the domains, main page source and iFrame source, are different). Other examples of third party cookies are images or other objects contained in a Web page may reside in servers different from the one holding the page. In order to show such a page, the browser downloads all these objects, possibly receiving cookies. These cookies are called third-party cookies if the server sending them is located outside the domain of the Web page. Some browsers allow third party cookies and in some browsers, like Internet Explorer, it depends on the privacy settings of the browser. In IE6 (Internet Explorer 6) with the default privacy setting of ‘Medium’, third party cookies will be deleted. As it turns out, there is a simple solution. If you supply a ‘compact privacy policy’ with your page, then IE will treat the cookies with respect and let them through.

The code

Just add this to the start of your page (every page where cookies will be written):

How to set p3p http header in ASP.Net?

HttpContext.Current.Response.AddHeader("p3p", "CP=\""IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""")
Code language: Java (java)

How to set p3p http header in PHP?

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
Code language: PHP (php)

How to set p3p http header in JSP?

response.setHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'")
Code language: Java (java)

How to set p3p http header in ColdFusion?

<cfheader name="P3P" value="CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'" />
Code language: HTML, XML (xml)
The above code will set P3P (Platform for Privacy Preferences Project) header. It allows the browser (specially Internet Explorer) to through all the third-party cookies (which may be set through iFrame).

View Comments

Share
Published by
Gaurav Patel
Tags: header P3P Platform for Privacy Preferences Project third party cookies

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago