0

I have a module that simply has a couple functions that retrieve cookie information, set cookie information and calls a web service using the web service client to help track the users information. However, when i installed the module, it did not recognize the function that executes the loading of the service from the web service client. It returned the following error:

Call to undefined function wsclient_service_load()

The code is simple and looks like this:

function set_session_tracking_data() {
$sessionGuid = com_create_guid();

//Time for Cookie Experation
$time = time()+3600;

if (isset($_COOKIE["Drupal_VisitorGUID"])) {
    $sessionId = $_COOKIE["Drupal_VisitorGUID"];
}
else {
    $sessionId = $sessionGuid;

    setcookie('Drupal_VisitorGUID', $sessionId, $time);

    $params = array('visitorGuid' => $sessionGuid);   
    $service = wsclient_service_load('tracking');
    $result = $service->CreateVisitor($params);
}
}

The function set_session_tracking_data is being called from a module created solely for tracking purposes. It has no hooks. Simply has a function called set_tracking_params() and in that function we call set_session_tracking_data(). The code is below:

function set_tracking_params() {
//Sets Module Path
$modulePath = drupal_get_path('module', 'eddy_tracking');

//Time for Cookie Experation
$time = time()+3600;

if (!isset($_COOKIE["cid"]) && !empty($_GET['cid'])) {
    setcookie('cid', $_GET['cid'], $time);
    dsm($_COOKIE["tsource"]);
}

if (isset($_COOKIE["key"]) && empty($_GET['key'])) {
    setcookie('key', $_GET['key'], $time);
}

set_tracking_params()
}
set_eddy_tracking_params();

I made the wsclient a dependency but it still does not recognize the function. If i put this same code within a block module i created, the code executes without a hitch. Can someone please help me with this issue? Or perhaps someone can mention to me the best practice at setting sessions and tracking a users session. Any help would be greatly aprreciated. Thanks!

  • Where are you making the call to set_session_tracking_data() from? – Clive Mar 29 '12 at 17:26
  • What context is it being called in? Is it in a hook_init(), hook_node_view() etc? – Clive Mar 29 '12 at 17:50
  • I updated my question to show where it is being called from. Should it be called inside a hook_init()? Clive - thanks for your help. I appreciate it. – Alex Mar 29 '12 at 17:52
  • No probs, I've added an answer but I'm not sure I've grasped exactly how your code should work...let me know if it helps – Clive Mar 29 '12 at 18:00
2

There seems to be a bit of confusion in your code: the set_tracking_params() function calls itself, which would would result in an infinite recursion.

That being said, you're calling the set_eddy_tracking_params () function directly in the PHP file which means it will probably be executed before Drupal's full bootstrap has run, and before the wsclient module file has been loaded.

If you're trying to run this function on every page then hook_init() would be the best place for it; it's called early on in every page load:

function MODULENAME_init() {
  set_eddy_tracking_params();
}
  • That is exactly what i was looking for and not sure why i hadnt thought about that. Thanks again for your help! – Alex Mar 29 '12 at 18:44
  • @Alex no worries :) – Clive Mar 29 '12 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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