Hello, help please? I wish to develop a module to do something very simple with PHP. I am challenged by the Drupal API. I am using version 6.
Goal:
1) Determine if user is viewing a particular node (role is irrelevant) 2) If yes, check to see if cookie is set a) If cookie is set, do nothing b) If cookie is not set, then set cookie and then redirect user to another node
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. THANK YOU SO MUCH!
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 blah 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
}
}
}
REVISED VERSION (THE LATEST)
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 durz Exp $
function offer_survey_init() {
global $base_url;
$offer_survey = true;
$cookie_name = 'survey_offered';
if (arg(0) === "testing") { // the path of the page
if (!$_COOKIE[$cookie_name]) {
setcookie($cookie_name,1,time() + (86400 * 365));
drupal_goto('new-destination'); // the path to be redirected to
}
}
}