1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple PHP Code To Pass Cookie Variable

Discussion in 'PHP' started by imarketing101, Jul 19, 2010.

  1. #1
    I placed a post on the clickbank forum but judging by the responses I get the feeling I placed it in the wrong part.

    You can view the original thread here: http://forums.digitalpoint.com/showthread.php?t=1877319

    What I want to do is to pass the clickbank affiliate ID from the cookie to my referral system and newsletter. How do I put it on the site as PHP?

    <?php
    if (isset($_COOKIE["hop"]))
      echo "http://" . $_COOKIE["hop"] . "hop.clickbank.net";
    else
      echo "http://www.mydomain.com/";
    ?>
    PHP:
    Doesn't seem like I got it right... Can anyone help?

    Maybe "hop" isn't the right variable?

    *apologies for the double post but I though the Clickbank section would've been the right place*
     
    imarketing101, Jul 19, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Read this for more information about cookies.

    I don't get it, just what are you trying to do? First of all, you have to be certain that $_COOKIE["hop"] contains the variable you need (affiliate ID), then pass it to your referral system. I don't know how your referral system but what you're doing on that piece of PHP code is just display it. =/

    I read that other thread and I wanna point out what this guy said:
     
    Rainulf, Jul 20, 2010 IP
  3. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, I think i didn't explain well. ClickBank sets a cookie when someone clicks on the affiliate link (maybe this explains it better: http://www.clickbank.com/help/affiliate-help/affiliate-basics/all-about-hoplinks)

    I just want to get the part of this cookie that credits the affiliate and repeat the link on the page so that when the user submits a form it will send the code to my aweber.

    Sorry, the PHP I had created was just to test that I could display it on the page.

    Makes sense?
     
    imarketing101, Jul 20, 2010 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Ah I see. But from my understanding, $_COOKIE only fetches cookies you've created, not ClickBank's cookies. I don't think it would work with $_COOKIE alone.
     
    Rainulf, Jul 20, 2010 IP
  5. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Could I use the ?hop=xxxxx passed at the end of my URL to be set in a cookie and the use the cookie to do this? I tried the guide you posted above - http://www.w3schools.com/PHP/php_cookies.asp - but it didn't quite work.
     
    imarketing101, Jul 20, 2010 IP
  6. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm close to the solution, but I'm getting the code wrong.

    My idea was, to get the ?hop=xxxxx that comes after the domain when it comes from a clickbank link and set that as a cookie:

    <?php
    if(isset($_GET['hop'])){
    	header( 'Location: http://www.mydomain.com/' ) ;
        setcookie("cbhop", $_GET['hop'], time()+2592000);
    }
    ?>
    PHP:
    However, I keep getting this error: Warning: Cannot modify header information - headers already sent

    The idea would be to use the following code to get the affiliate link wherever I want.

    <?php
    if (isset($_COOKIE['cbhop']))
      echo "http://" . $_COOKIE['cbhop'] . "hop.clickbank.net";
    else
      echo "http://www.mydomain.com/";
    ?>
    PHP:
    Can anyone help?
     
    imarketing101, Jul 20, 2010 IP
  7. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #7
    Try to add this just after <?php
    ob_start( );
    PHP:
    And this before ?>
    ob_end_flush( );
    PHP:
    By the way, you don't need cookies to do something like that..
    
    <?php
    ob_start( );
    if(isset($_GET['hop'])){
       $poop = $_GET['hop'];
       header("Location: http://" . $poop . "hop.clickbank.net");
    }
    ob_end_flush( );
    ?>
    
    PHP:
    try .. yourwebsite.com/thisscript.php?hop=watever
     
    Last edited: Jul 20, 2010
    Rainulf, Jul 20, 2010 IP
  8. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Oh, I do - because the ?hop is set on one page (mydomain.com/?hop=xxx) and the affiliate code is passed on in another page.

    Such as mydomain.com/newsletter.php. Also, I want to track the cookie for 30 days so if they come to the site later, the affiliate still gets credited.

    Will the code above work for this?
     
    imarketing101, Jul 20, 2010 IP
  9. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #9
    You definitely need cookies then. Here:
    
    <?php
    ob_start( );
    if(isset($_GET['hop'])){
        setcookie("cbhop", $_GET['hop'], time()+2592000);
        header( 'Location: http://www.mydomain.com/' ) ;
    }
    ob_end_flush( );
    ?>
    
    PHP:
    And the other one:
    
    <?php
    ob_start( );
    if (isset($_COOKIE['cbhop']))
      echo "http://" . $_COOKIE['cbhop'] . "hop.clickbank.net";
    else
      echo "http://www.mydomain.com/";
    ob_end_flush( );
    ?>
    
    PHP:
     
    Rainulf, Jul 20, 2010 IP
    imarketing101 likes this.
  10. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi Rainulf, I haven't tested this yet, but you've been great help. I tried to give you Karma. Hope it worked.
     
    imarketing101, Jul 20, 2010 IP
  11. imarketing101

    imarketing101 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Works!

    Thank you!
     
    imarketing101, Jul 20, 2010 IP