Entering PHP Code Directly into a Record

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2011   (RSS)

By Perchpole - April 11, 2011

I know this has been raised before but is there still no way to enter php code into a CMSB record and have it render as if it had been added directly to the page template?

Currently, if you enter some php code into a text box - such as...

<?php showme($record); ?>

...it would actually render as...

<!--?php showme($record); ?-->

Which makes it useless!

I assume this is some form of safety mechanism to ensure malicious code is not injected into pages. However, there are times when the ability to enter code into CMSB record directly would be most useful.

Is there any way we can achieve this? Could we not have a special "code" field type set-up in the Section Editors? Anything entered into it would be handled/run as proper php code.

:o/

Perchpole

Re: [Perchpole] Entering PHP Code Directly into a Record

By Dave - April 11, 2011

Hi Perch,

It is possible, but usually a really bad idea for security and usability reasons.

What are you trying to accomplish? Maybe there's a better or simpler way.
Dave Edis - Senior Developer
interactivetools.com

Re: [Perchpole] Entering PHP Code Directly into a Record

By Dave - April 11, 2011

Hi Perch,

Well if you really want to do it, the way to run PHP code is like this:
<?php echo eval( $record['phpcode'] ); ?>

But I don't recommend that unless you absolutely trust everyone who has access to your CMS because you'll be giving them the ability to run any code on your server.

Another way, would be to have a list of include files and then include them like this:

if ($record['includeFile1']) { include "/includes/" .$record['includeFile1']. ".php"; }

And then you could add a security check to make sure it only contained letters or was in a list of pre-approved files.

So there's a few options. Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Entering PHP Code Directly into a Record

By Perchpole - April 11, 2011

Thanks Dave -

And understood. I'll explore a lot further before I go live with this.

:0)

Perch