Hi all

I am looking for a quick solution to a problem I'm having, I will pay $50 via paypal or if you're in Canada I will send you email interac.

I want to set a cookie when people enter the site (Drupal 6) which is HTTP_REFERER. I then want to retrieve this cookie for a webform entry.

Let me know.

Thanks

I was trying to add the below entry to page.tpl.php,

if ($node->type=='page')): $referer = getenv("HTTP_REFERER"); setcookie('TestCookie', $referer, time()+(86400*30)); endif;

I then have a hidden entry in the webform with a value of %cookie[TestCookie]. However this isn't being picked up within webform so obviously isn't correct. I also tried setting a basic cookie which also isn't picked up.

Comments

paulnem’s picture

BTW, typo in that php code, an additional ) which I've already removed.

kbahey’s picture

There are two issues with your code:

1. As a rule, you should not store any data client side, because it can be faked and tampered with. It is better to store the referer in $_SESSION['referer'], so it gets saved server side.

2. Placing this in page.tpl.php will cause the referer to be overwritten every page refresh, so, you have to set the $_SESSION[] variable only once, for example, if it is not set.

if (!$_SESSION['referer']) {
  $_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
}

If it was me, I would put this in new module, in hook_init() rather than in page.tpl.php.

You can then try using %session in webform to retrieve this.

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

josepvalls’s picture

I recently had a similar issue with webforms.
WARNING, if you enable catching, the webform generation will be catched and therefore the referrer code will be misleading.