/    Sign up×
Community /Pin to ProfileBookmark

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.

[code=php] <?
// 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” />[/code]

The cookie file is called “[email protected]

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

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Li0rEJun 02.2006 — It shouldnt be that hard, what you have to do is this.

<?

$affiliate = $_COOKIE['AffiliateID'];

mail("Your Name <[email protected]>", "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 protected]>");

?>[/QUOTE]


And it might not be reading right because you arent setting the cookie correctly.
Copy linkTweet thisAlerts:
@bldstrauthorJun 02.2006 — Thanks for your reply. Unfortunately, there is a [B]lot[/B] 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 :o There's a complicated Java back-end to the affiliate tracking.
Copy linkTweet thisAlerts:
@bokehJun 02.2006 — 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?
Copy linkTweet thisAlerts:
@bldstrauthorJun 02.2006 — 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
×

Success!

Help @bldstr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...