I am storing a session value via Rules when the user is logged in

$_SESSION['userkey'] = "12345";

Also testing it below there

echo $_SESSION['userkey'];

Although when I am trying to retrieve this value in my view in a field as Global: PHP

with Value Code:

return $_SESSION['userkey'];

Output code:

echo $value;

It does not return anything. Unsure whether the session is not being set properly or I am retrieving the value incorrectly?


  • Check Drupal logs or Apache/PHP logs and see if you have an error of level E_NOTICE – Aboodred1 Oct 29 '14 at 12:43

You need to remove session_start() from Rules. Drupal calls session_start() when firing drupal_session_start().

Check out session_start manual on php.net

As of PHP 4.3.3, calling session_start() after the session was previously started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.

Screenshot for PHP field settings in Views:

enter image description here

  • I feel its an issue somewhere on the views side, with or without session_start, I am unable to retrieve the value in the view fields – pal4life Oct 29 '14 at 17:00
  • @pal4life I was able to get session value the way you describe it without session_start just fine. Try to update views_php module and see if it solve your issue. – Aboodred1 Oct 29 '14 at 17:24
  • Thanks for your response, What code did you add in the value code and output code field in your views to get the value? – pal4life Oct 29 '14 at 17:32
  • 1
    @pal4life I added a screenshot in my answer for PHP field settings, check it out and I hope it will for you as well. Make sure to logout and login to see the value on your views. – Aboodred1 Oct 29 '14 at 18:07
  • 1
    This is awesome, thanks for the screenshot. This made things very clear. Certainly a picture is worth a thousand words. Thanks. – pal4life Oct 30 '14 at 0:43

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.