I want to restrict my page access. Only an administrator should be able to see the page.
I followed this tutorial
function example_menu() {
$items['example'] = array(
'title' => 'My Page',
'page callback' => 'example_custom_page',
'access callback' => 'example_user_has_role',
'access arguments' => array(1, array('adminstrator')), // Argument 1 loads the user, argument 2 is the role name.
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function check_user_has_role($user, $roles = array()) {
foreach ($roles as $role) {
if (in_array($role, $user->roles)) {
return TRUE;
}
}
return FALSE;
}
But I was able to access the URL even after I logged out. What is my mistake or is there a better way to achieve this?