EllisLab text mark
Advanced Search
     
php within templates - good or bad?
Posted: 07 July 2012 02:32 AM   [ Ignore ]
Joined: 2012-04-29
55 posts

EE allows for PHP to be embedded within templates. This seems to be rather frowned upon. I don’t fully understand the issues here. Could anybody offer an explanation.

 
Posted: 07 July 2012 04:42 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-06
375 posts

If you’re working on a client site, and they’ll have access to the templates, they could really break stuff/create massive security holes if php is enabled. If it’s your own site, or template access will be tightly controlled, there are things that can be done with straight php that are damn near impossible otherwise - mainly because of parse order issues.

 Signature 

TucsonSentinel.com - we’re watching Tucson

LIONpublishers.com - Local Independent Online News Publishers

 
Posted: 07 July 2012 05:04 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-04-29
55 posts

Thank you Dylan, that is just the problem I’ve run into, I could not squeeze what I wanted out existing tags.  What might be an example of a security hole? Just to make sure I avoid!

 
Posted: 07 July 2012 05:03 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-06
375 posts

“Enabling PHP in a template will enable anyone with editing rights for that template to become a de-facto Super Admin since they can execute any PHP they want in that template, including PHP that can reveal information about your system, PHP that can delete data from your database, etc. Exercise extreme caution before enabling this option if you permit others to edit your templates.”

http://ellislab.com/expressionengine/user-guide/templates/php.html

 

 Signature 

TucsonSentinel.com - we’re watching Tucson

LIONpublishers.com - Local Independent Online News Publishers

 
Posted: 08 July 2012 04:21 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-04-29
55 posts

Brilliant fully understand that now. I have careful control over templates so it should not present an issue. Thank you for explaining.

 
Posted: 18 July 2012 09:53 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-11-08
211 posts

Another thing to consider is writing a quick plugin. Often I’ll start with writing PHP in a template, and then convert it to a plugin. Makes templates clean and gives you the possibility to do anything using EE syntax.

Great starting point in creating a plugin: http://pkg.io/

 
Posted: 19 July 2012 04:12 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-04-29
55 posts

Thank you excellent pointer.  The mere word “plugin” has me feared.  I did not see it as a natural extension of some of the things I am already doing, will give it a go!