1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

script for viewing stored cookies?

Discussion in 'HTML & JavaScript' started by Black121, Feb 23, 2011.

  1. Black121

    Black121 Newbie

    Joined:
    Feb 23, 2011
    Messages:
    2
    Likes Received:
    0
    Hey guys,
    Was wondering if anyone here has ever built a script that fires a different pixel based on the cookies it sees stored in a browser. I've been told it would be an if/then type of action but that's about as far as I've gotten. Any ideas?

    Thanks!
     
  2. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    Sure, first you need to set the cookie on whichever page you want:
    PHP:
    <?
    // sets a cookie named cookieName storing cookieValue for 100 days
    setcookie("cookieName""cookieValue"time()+60*60*24*100);
    ?>
    Then on the page that needs the pixel fire:
    PHP:
    <?
    $myCookie $_COOKIE["cookieName"];
    if (
    $myCookie == "desiredCookieValue")
         echo 
    "pixel fire 1";
    else
         echo 
    "pixel fire 2";
    ?>
    But that just covers 2 cookie values. To do do 3+, you can use else if rather than else.

    PHP:
    <?
    $myCookie $_COOKIE["cookieName"];
    if (
    $myCookie == "desiredCookieValue")
         echo 
    "pixel fire 1";
    else if (
    $myCookie == "desiredCookieValue2")
         echo 
    "pixel fire 2";
    else if (
    $myCookie == "desiredCookieValue3")
         echo 
    "pixel fire 3";
    ?>
     
    • Thanks Thanks x 3
  3. Black121

    Black121 Newbie

    Joined:
    Feb 23, 2011
    Messages:
    2
    Likes Received:
    0
    Thanks man! I really appreciate it.

    Any idea how I would set that up to see if another site's cookie was stored in their browser as well? I'd like to fire a specific pixel on them based on whether they had been in to a competitor's site before. Is that possible?
     
  4. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    No it is not.
     
  5. RandR

    RandR Registered Member

    Joined:
    May 18, 2009
    Messages:
    75
    Likes Received:
    25
    Home Page:
    To elaborate, cookies are domain specific (for obvious security reasons). Cookies can only read if the domain making the request matches the domain of the cookie.