Setting page permissions in drupal

I am new to drupal. I think this is a very stupid question. I have included the PHP filtering module so that I can create a new page with my own PHP code. On this page, I want to be accessible only to authenticated users that are not displayed to anonymous users. How can i achieve this? Can I set permissions for individual pages in drupal? Or can it be determined that an anonymous user is trying to access the current page through PHP code?

+5
source share
3 answers

Since you mentioned that you are new to Drupal, a caution is that using a PHP filter for your custom code is considered bad practice. This is a hack and a security issue.

It is much better to write your own custom module, and it can implement its own custom permissions that you can check, etc. etc. There is a good sample module that you can check to see how it should look. Obviously, look and a guide. It really is not as difficult as it seems.

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

global $user;

, . $user->roles - , . , authenticated user ( - ).

+5

, . , PHP ( - ), simple .

+4

, php:

<?php
// we have to access the content of the global-scope variable $user
global $user; 

//Checking if the user is registered
if (in_array('authenticated user', $user->roles)==FALSE) {
header('Location:/content/restrictedaccess') ;
}
?>

//

- , Drupal : http://modeling-languages.com/content/how-i-created-site-drupal

+2
source

All Articles