1

I am using the phpCAS library and would like sessions to be handled by that library.

I am instantiating the client this way:

function my_module_init(){
    ...
    phpCAS::client(CAS_VERSION_2_0,'casdomain' , 8443, '/cas',true);
    ...
}

I have it in hook_init() since I want to check for user authentication on each page load.

But I am getting this error.

phpCAS error: phpCAS::client(): Another session was started before phpcas. Either disable the session handling for phpcas in the client() call or modify your application to leave session handling to phpcas

How can I get rid of this error and have phpCAS handle the session?

Thanks.

2 Answers 2

1

Any reason why you are not using the module cas? It seems like a fairly stable module with over 5000 people using it. I would give that a shot before attempting any custom code in hook_init().

4
  • That module does not handle Single Sign Out. And it can't since that module does not manage the session which I am trying to do.
    – rexposadas
    Nov 15, 2012 at 22:50
  • Surely it would be better to handle this as a patch to the module (and upstream it) versus rolling your own custom authentication module. Just think of the next guy to come across your code.
    – wiifm
    Nov 16, 2012 at 8:05
  • 1
    Looking at the code for 7.x-1.x-dev there is indeed code for hook_logout() to manage single sign out across CAS.
    – wiifm
    Nov 16, 2012 at 8:11
  • I stand corrected. That module does have code for single sign out. Currently, I am having problem just logging in to CAS using that module. Once I get things working I'll update this question.
    – rexposadas
    Nov 19, 2012 at 19:45
1
  1. Create a copy of session.inc in your modules folder. I named my mymodule.session.inc.
  2. In mymodule.session.inc find the function drupal_session_initialize() and replace drupal_session_start() with the call to the of the CAS client constructor.
  3. In your module's .install file set the location of mymodule.session.inc file

    function mymodule_install() { variable_set('session_inc', 'path/mymodule_session.inc'); }

    function mymodule_uninstall() { variable_del('session_inc'); }

As a result Drupal will create the CAS client before any session is created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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