Listing and Checking Drupal Permissions through Code

The following lists all the permissions available in Drupal.

<?php
// Render role/permission overview:
$options = array();
foreach (
module_list(FALSE, FALSE, TRUE) as $module) {
 
print_r($module);
 
// Drupal 6
  // if ($permissions = module_invoke($module, 'perm')) {
  //  print_r($permissions);
  // }

  // Drupal 7
 
if ($permissions = module_invoke($module, 'permission')) {
   
print_r($permissions);
  }
}
?>

You could check whether a particular permission is set or not using the following:

<?php
 user_access
($string, $account = NULL)
?>