Thursday, September 15, 2011

demo code to test third party cookie

Hi Folks,

Here i am sharing code snippets that i use to test and understand cookie. Specially third party cookie.

What i did ?
Actually i create two sub domains and
then i tried set cookie across domains.

How i did it ?
I wrote php code which set cookie and then convert out header as image with content. and then use IMG html tag with src that PHP script.

PHP code:


/* The next four values may be changed. */
$CookieName = "mycookie";    // Cookie's name
$CookieValue = "hello Ravi"; // Cookie's value
$CookieDirectory = "/";        // Cookie directory ("/" for all directories)
$DaysCookieShallLast = 31;     // Days before expiration (decimal number okay.)
$CookieDomain = '';
$lasting = ($DaysCookieShallLast<=0) ? "" : time()+($DaysCookieShallLast*24*60*60);
header('Content-type: image/gif');
echo base64_decode($image);

HTML Code at


function getCookie(c_name)
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  if (x==c_name)
    return unescape(y);
<?php echo $_COOKIE["mycookie"]; ?>

Hope code will be helpful to understand what i said in my previous post.

Happy coding !!!

No comments:

Post a Comment