Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting page access permissions in drupal

Tags:

drupal

I'm new to drupal. Its a very dumb question I guess. I have enabled PHP filter module so that I can create a new page with my own PHP code in it. This particular page I want to be accessible to only authenticated users, not visible to anonymous users. How can I achieve this? Can I set permissions for individual pages in drupal? Or is it possible to identify that an anonymous user is trying to access the current page through PHP code?

like image 899
Niks Avatar asked Sep 19 '09 10:09

Niks


Video Answer


2 Answers

Since you've mentioned you're new to Drupal, a word of caution - using PHP filter for your custom code is considered bad practice. It's a hack and it's a security problem.

It's much better to write your custom module, and it can implement its own custom permissions, that you can check for, etc. etc. There's a nice sample module that you can check out to see how it should look. Obviously, check out the handbook as well. It's really not as hard as it sounds.

But back to your question. You can put the following line in your PHP-filtered page:

global $user;

This will give you access to an object that represents the current user. $user->roles is an array that represents the user's roles. You can just check if it has authenticated user (or slightly better - a custom role you create).

like image 179
Eli Krupitsky Avatar answered Sep 29 '22 16:09

Eli Krupitsky


Having read above answers, you may also consider the readily available simple access module. It suited my requirements and if you're to avoid PHP filtering and don't want to create your own module (for whatever reasons), you can check out simple access.

like image 43
Niks Avatar answered Sep 29 '22 14:09

Niks