Snippets for eZ publish 3: Logging in a specific user

Code sample

The following code will login the user with the login specified by $login. It is especially useful in cronjob scripts when you need sufficient privileges.

require_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
$user = eZUser::fetchByName( $login );
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );


In all recent versions of eZ publish the content/read policy limitation list of the current user gets cached in a global array by eZContentObjectTreeNode. When switching users, this cache isn't cleared. This issue has been reported as bug 8388 at

You can workaround this problem by clearing the cache yourself with the following code:

if ( isset( $GLOBALS['ezpolicylimitation_list']['content']['read'] ) )
    unset( $GLOBALS['ezpolicylimitation_list']['content']['read'] );