www.webdeveloper.com
Results 1 to 5 of 5

Thread: PHP Form + Cookie problems

  1. #1
    Join Date
    Nov 2005
    Location
    Scotland, UK
    Posts
    149

    PHP Form + Cookie problems

    Trying to do something pretty basic here.

    There's a cookie, which is set as a user visits one of our affiliate pages, called AffiliateID. I would like to extract the ID from the cookie and put it in an empty form field to be passed on to another PHP doc which creates and sends an email to me. According to my temporary echo though, the cookie is not being read.

    PHP Code:
      <?
    // Reads cookie: 

      
    $_COOKIE['AffiliateID'];
      
      echo 
    "Affiliate ID=".$_COOKIE['AffiliateID'];
      
      
    ?>
      
    <form name="finance-app" method="post" action="finance-enqiry.php" onSubmit="return process();">

    <input type="hidden" value="<? echo $_COOKIE["AffiliateID"]?>" name="affID" />
    The cookie file is called "user@www.buildstore.co"

    Can anyone help? This is my first time working with PHP and cookies.

  2. #2
    Join Date
    Jun 2006
    Posts
    15
    It shouldnt be that hard, what you have to do is this.
    <?
    $affiliate = $_COOKIE['AffiliateID'];
    mail("Your Name <youremail@yourwebsite.com>", "A user has just visited an affiliate website $affiliate.", "Hello, this email has just been sent to confirm that a user has visited the website of $affiliate.", "From: Affiliate Confirmation <affiliate_conf@yoursite.com>");
    ?>
    And it might not be reading right because you arent setting the cookie correctly.

  3. #3
    Join Date
    Nov 2005
    Location
    Scotland, UK
    Posts
    149
    Thanks for your reply. Unfortunately, there is a lot more to this form than what I posted, 40-50 fields in fact, and the affiliate ID must be attatched to this. The form goes through some JavaScript validation too before being passed to the next PHP document.

    I've been reading more on cookies and it seems my problem is actually the path There's a complicated Java back-end to the affiliate tracking.

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,736
    If the cookie is not being echoed you need to check if it is being set at all. Are you trying to set it and read it on the same page?

  5. #5
    Join Date
    Nov 2005
    Location
    Scotland, UK
    Posts
    149
    I put in some code to create a cookie, it works fine and passes the variable to the next PHP doc. Seems it is due to the path where the cookie is originally created and restricted to.

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles