2

This is my first official post so bare with me if i do not have all the information you may need.

Being a beginner of Drupal from a PHP background I am struggling with SESSIONS.

First, there are conflicting information I am reading on how one should set sessions, some say it we should use a unique key, like so: $_SESSION["uniquekey"] = array(); $_SESSION["uniquekey"]["variable"] = 1;

Others say this is sufficient:

$_SESSION["variable"] = 1;

Secondly, I have managed to set Anonymous sessions without problems, this sets the UID to 0 in the sessions table, the problem I am experiencing is when I login.

Login is succeeding but I am getting "you have no authentication etc" and therefore unable to access the CMS. FYI in the session table, it has inserted another session with UID set as 1. I am having to destroy the anonymous session to access the whole CMS but from what I understand the login form should regenerate?

I am setting the sessions in template.php and logging in user /user

Would appreciate if some people can share some light on how one can set sessions without breaking the login?

Your help would be much appreciated

Cheers

1
  • Drupal sets its own sessions... are you creating new sessions or just setting session variables? can you explain what your end goal is?
    – user5482
    Apr 20, 2015 at 13:12

1 Answer 1

0

If you are actually trying to override the default behaviour of assigning uid, you need to explain why. In order to access the already determined uid information created by Drupal, use this in template.php or a .tpl.php:

<?php
  global $user;
?>

To see what information is already available in $user, make use of the Devel Module:

Helper functions for Drupal developers and inquisitive admins. This module can print a summary of all database queries for each page request at the bottom of each page. The summary includes how many times each query was executed on a page (shouldn't run same query multiple times), and how long each query took (short is good - use cache for complex queries).

specifically, the dpm() function. This can be added just about anywhere as:

<?
  php global $user;
  dpm($user);
?>

This will present a breakdown of the $user array and all the information it contains.

Your Answer

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

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