By stoob on
Hello, help please? I wish to develop a module to do something very simple. I am challenged by the Drupal API.
Goal:
1) Determine if user is viewing a particular node (role is irrelevant)
2) If yes, check to see if cookie is set
That's it!
I have created a module and installed it, there is no error yet it also does nothing. No cookie is set. I am not sure how the Drupal system likes to redirect requests so insight there would be helpful, please.
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 Stoob Exp $
function offer_survey_init() {
global $base_url;
$offer_survey = true;
$cookie_name = 'survey_offered';
if ($node->nid == 651) {
if ($_COOKIE[$cookie_name]) {
// do nothing
} else {
setcookie($cookie_name,1,time() + (86400 * 365));
//then do the redirect an internal webform URL
}
}
}
Comments
You reference $nod->nid but
You reference $nod->nid but $node does not exist in the local function scope. You should be able to use arg(1). So if (arg(1) == 651)
thank you. this is my revised code. it now works
contents of modulename.module file:
good!
good!
Set cookie for author of landing page
Could this code, in some adapted way, be used to set a cookie for the author of the landing page (all user roles) and later be retrieved through view to use it in an external URL? The intention is to know which user-input page generated the visit in case of sales and use his/her reference to for sharing revenue.
In case of answer you should start to explain from the beginning, I don't know how to set cookie in the first place, nor how or where to put the corresponding code (php-block?).
I started with Drupal in 2007 and then my life got stuck...
setcookie is easy, using the
setcookie is easy, using the setcookie() php function
I do not understand what your goal is. I am sorry but I am too busy to help you, and this project was almost two years ago, I don't remember much about it. Good luck.