Do things like anonymous users programmatically

Public

Get raw version
php
  1. // Prevent session information from being rendered.
  2. drupal_save_session(FALSE);
  3. // Force the current user to anonymous to prevent access bypass.
  4. $original_user = $GLOBALS['user'];
  5. $GLOBALS['user'] = drupal_anonymous_user();
  6.  
  7. // Render an entity as anonymous user should see.
  8. $node = entity_load('node', array($nid => $nid));
  9. $entity_view = entity_view('node', array(entity_id('node', $node) => $node), 'full');
  10.  
  11. // Restore the user.
  12. $GLOBALS['user'] = $original_user;
  13. drupal_save_session(TRUE);