Beginners of drupal will always find a way to put their php code in drupal. If you couldn’t run the php code. It means you are not aware of “php filter module“. This post will help you to know about php filter module and a way to put your php code in drupal.
You can make the php code run in any body area of drupal. But here we will begin with creating a block, naming it, and putting the php code in the body section of the block. Then assigning the block to a region to view the output of the php code.
Go to Administration => Structure => Blocks => Add Block to add a block, you will find the following page,
Name the block and fill its description. then you will find a drop down select field “Text Format”. you will find “PHP code” as an option. Choose it and write your php code in the body section.
If you dont find “PHP code” option. You have to enable the “PHP filter module“. Go to Administration => Modules. Scroll down to the PHP filter module and check the Enabled box. Press the Save Configuration button.
Again scroll down to the same PHP filter module, you will find permissions link. Click on this to go to the Permissions page, Scroll down to the Filter section and you will find a new item called “Use the PHP code text format”.It’s checkbox for the Administrator is not checked. Check the box and save the permission page. Now u r ready to put your php code anywhere in the drupal content area.
Go to Administration => Structure => Blocks, then click on the “configure” link next to your block. Scroll down to the Text Format dropdown. You should see a new option called “PHP code”. Select it.
Write your php code in the body section and assign the block to a region. Save the block and view the php code output in that region.