How to save the URL of anonymous user on a webform? Using Webform 7.x-3.18, I'd like to save the referring URL of an anonymous visitor on a webform. I added some code to MYTHEME__preprocess_page() in template.php to save the info as a cookie:
user_cookie_save(array('webform_referrer' => $_SERVER['HTTP_REFERER']));

On my webform I added a hidden component, with a default value of %cookie[Drupal_visitor_webform_referrer].

I'm testing with safari/chrome/ff on a Mac and on Windows. I can get this to work on my local testserver, but only about 10% of the time on the production server, and never from Windows to the production server. The production server has hardware load balancing. I'm suspecting this is a caching issue. I've also read that server vars may not be available as webform default values for anon users (http://drupal.org/node/296453#comment-2397674) - is this the issue? Why then would it be working for anon users coming to my local server?

I can't think of another way to integrate this easily into webform as a hidden field. Perhaps I have to write some kind of custom hander to save the referrer?
So you can achieve this using form alter, 

create a text field namely 'refer_url' for saving referring url, then using following snippet in your module you can save the referring url. You can hide this field in display using css or form alter.

function module_name_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form_id == 'webform_client_form_27') { 
    $form['submitted']['refer_url']['#default_value'] = $_SERVER['HTTP_REFERER'];
    }
}