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.
The cookie file is called "email@example.com"
// Reads cookie:
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" />
Can anyone help? This is my first time working with PHP and cookies.
It shouldnt be that hard, what you have to do is this.
And it might not be reading right because you arent setting the cookie correctly.
$affiliate = $_COOKIE['AffiliateID'];
mail("Your Name <firstname.lastname@example.org>", "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 <email@example.com>");
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.
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?
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)