Posted by joshk on September 10, 2010 at 10:11pm
6 followers
| Project: | Masquerade |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | claudiu.cristea |
| Status: | closed (duplicate) |
Issue Summary
Masquerade's hook_init has an incompatibility with Pressflow in that it initializes a $_SESSION for every pageload whether this is necessary or not:
<?php
/**
* Implementation of hook_init().
*/
function masquerade_init() {
global $user;
// load from table uid + session id
$uid = db_result(db_query("SELECT uid_from FROM {masquerade} WHERE sid = '%s' AND uid_as = %d", session_id(), $user->uid));
// using if so that we get unset rather than false if not masqing
if ($uid) {
$_SESSION['masquerading'] = $uid;
}
else {
$_SESSION['masquerading'] = null;
}
}
?>I believe the fix is as simple as changing the else statement to be like:
<?php
elseif (isset($_SESSION['masquerading'])) {
$_SESSION['masquerading'] = NULL;
}
?>Patch is attached.
| Attachment | Size |
|---|---|
| masquerade_pressflow_compatibility.patch | 573 bytes |
Comments
#1
Lets get this committed!
#2
Committed to DRUPAL-6--1. HEAD and DRUPAL-5 do this process differently, so I didn't apply it there.
#3
Just to confirm, this is a duplicate of #705858: Don't create session var when not masqerading?
Marking as to be ported to remind myself to double check this against HEAD.
#4
Right now, with the code from DRUPAL-6--1 when we masquerade as Anonymous (UID = 0) we are loosing the source user in $_SESSION['masquerade'] because the code from hook_init() triggers only when user_is_logged_in().
#5
Here's a patch that strips out session variable
$_SESSION['masquerading']when the current user is not masque (not set through Masquerade). The result is that when not masquerading there will be no$_SESSION['masquerading']variable.When masquerading there will be a
$_SESSION['masquerading']variable even if masquerading as Anonymous. And this is the right behavior even on Pressflow.Modified also all occurrences of
$_SESSION['masquerading']to make the code PHP 5.3 safe.#6
Isn't it safe to unset something that's not set? Can
if (isset($_SESSION['masquerading'])) {be removed in the init()?#7
There are more subscribers on the older issue: #705858: Don't create session var when not masqerading