Skip to main content

Check if user is 'logged in' or is 'admin'

Check if user is ‘logged in’ or is ‘admin’

If you have a Drupal 6 site, and need to secure a page so only users logged in can see it, do the following…

if(user_is_logged_in() != TRUE){
   // Do stuff, i.e.
   // header('Location: /');
   // exit('You do not have permission to view this page, please log in with the correct access.');
}

This makes use of the Drupal 6 function user_is_logged_in()

This can also be used in the page.tpl with a page title, (which uses the $title variable)…

if($title == 'Secured Page' && user_is_logged_in() == TRUE){
   // Do stuff that will only show if the page title is Secured Page and the user is logged in.
}

This can also be used to specify just the administrator, using the $is_admin variable…

if($is_admin != TRUE) {
   // Redirect or exit
   // header('Location: /');
   // exit('You do not have permission to view this page, please log in with the correct access.');
}
Main Category
  • Drupal
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • Handy Functions
    • MySQL
  • WordPress
  • About
  • Contact

BBC Technology News

  • Fast broadband roll-out begins
  • Gif inventor says pronounce it 'Jif'
  • Backlash over Xbox pre-owned games
  • Couple's £163,000 phone bill shock
  • Solar plane sets off again across US
More

Sitepoint

  • What’s New in Chrome 27
  • Comparing Ghost to the Big Three
  • Be Convincing and Win More Clients
  • Even Better CSS3 Toggle Switches!
  • Introducing the new HTML5 template Tag
More

Heart Internet

  • Resellers: New 14 day free trial feature added to SiteDesigner
  • New apprentice scheme at Heart Internet
  • Sale now on, get 50% off Web Hosting
  • 7 tips to kick-start your day in front of the computer
  • Link Friday Week #11
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
  • Contact
 

© Jon Moore 2013