The PHP SNIPPETS come with a brief introduction on what it does and if it only works with specific versions of Drupal.

Some are very similar to how you SETUP CUSTOM BLOCKS WITH CONTENT THAT APPEAR IN THE SIDEBARS but the snippets below are intended for use within your main NODE page as opposed to your sidebars.

Once you get used to how the PHP Snippets work and if you are familiar with how to setup up a HTML table or using DIVs, you can mix snippets together in the same page creating sophisticated layouts like those found at http://www.mtv.com or http://www.yahoo.com.

  1. Go to CREATE CONTENT -->> PAGE
  2. Give your page a TITLE
  3. In the BODY text area, paste in your PHP Snippet. Make sure you include the opening and closing PHP statements and remove any extra spaces, line breaks after the final ?> which tells drupal that this is the end of the php page.
  4. Select the PHP CODE filter.
  5. Click SUBMIT or PREVIEW to view your page.

Comments

leticia2602’s picture

To accomplish Step 4, first you must enable "PHP filter" module in Administer/Modules section.

dineshbonn’s picture

I enabled the PHP filter from the module section even after when i put the php code snippet in my page body it just display the code as it is .. Iam using drupal 6.10. What could be the problem?..

thank you..

sdeng’s picture

You actually enter the php as text that's why it displays the code itself. Follow this to solve, enable FCKeditor if you haven't, click tab "Source" on the first row of FCKeditor tool bar, paste the php code there, that means php code should be on source code interface not text interface. Finally save the change. It should solve the problem.

sghaznavi’s picture

I am running into the same problem attempting to run an embedded php snippet, even after enabling the PHP Filter Module.

Lexas’s picture

After doing so, you must go to Administer > Site config > Input formats, enter on formats that you wanna let PHP be used and chech "PHP evaluator".

webalchemist’s picture

wow, well this is somewhat confusing. I just spent about 10 minutes writing my code and inserting my custom functions into the page. As soon as I saved the page, my code did not work and drupal does not preserve the php script in my page. It seems like it sends the php to cache and only shows me the html output.

How can i preserve the php in the body?

ator1967b’s picture

Maybe the mistake is you tried to insert php code in a page. You must define a block and insert php code in it.

francescogiannico’s picture

I created a website and my friend need to insert php script into a page. This script should create the possibility to select region and city of Italy and obtain a list of result in that specific area. these informations are on an external oracle db.

I don't know much about php but I think that enabled php filter was ok inserting php code into the page called list_results.
But nothing appears.

I'm on drupal 7.15 thanks in advance for any info