0

I want to write referral URL to cookie and use it at some point to echo that referral URL on my website. What is the best way to achieve this?

Thank you

closed as off-topic by Rarst Oct 28 '14 at 17:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Generic PHP question in this form. If it has some WP aspects I am missing please elaborate and edit. – Rarst Oct 28 '14 at 17:56
  • I was thinking that it could be some WP function, but now I see that it is just PHP thing. Thanks. – MIC Oct 30 '14 at 9:03
1

You can do this as we do in PHP. You can set cookie following way.

setcookie( 'cookie-name', 'cookie-value', 'cookie-expiration-time', 'cookie-path', 'cookie-domain', false );

For referral url, I made following code that you can use to set a cookie with name my-referral-cookie and time() + 3600 (1 hour from current time) is expiration time for cookie.

setcookie( 'my-referral-cookie', $_SERVER['HTTP_REFERER'], time() + 3600, COOKIEPATH, COOKIE_DOMAIN, false );

You can get the value of cookie like this.

echo $_COOKIE['my-referral-cookie'];

That's it.

  • Thanks :) I was thinking that where could be some WP function or something. Quite simple :) thank you for your help! – MIC Oct 30 '14 at 9:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.