Page 1 of 1
How to add php code in a page ?
Posted: Mon Aug 20, 2007 11:45 pm
by david7594
Hello ! I would like to add php code in a page but i don't know how to do...
Thank you for your help
Re: How to add php code in a page ?
Posted: Tue Aug 21, 2007 3:56 am
by Nullig
The easiest way is with a User Defined Tag (UDT).
Nullig
Re: How to add php code in a page ?
Posted: Tue Aug 21, 2007 5:47 am
by cyberman
Another way is to set
Code: Select all
$config['use_smarty_php_tags'] = false;
in config.php to true so you can mask it in a page via {php}source{/php}. But it's risky if you have more than one user/admin ...
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 8:56 am
by tractorboy
I use a user-defined tag called extfiles whose content is one line :
include($params['filename']);
and is called like this :
{incfile filename='dynamic.php'}
Steve
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 9:04 am
by cyberman
Hi Steve,
nice solution too - will add this to wiki.
tractorboy wrote:
I use a user-defined tag called extfiles
...
and is called like this :
{incfile filename='dynamic.php'}
Think it must be

Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 9:15 am
by RonnyK
Cyberman,
extfiles neq extfile. UDT without the ending "s", as it calls a single file, {extfile....}
Ronny
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 9:18 am
by cyberman
Thanks Ronny - you were right.
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 11:37 am
by cyberman
cyberman wrote:
nice solution too - will add this to wiki.
It's done
http://wiki.cmsmadesimple.org/index.php/FAQ/Add_PHP
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 3:41 pm
by Pierre M.
Hello,
for security conscious webmasters, I think Nullig's UDT solution is the best : the executed PHP code in known in advance and maintained by its owner.
In others cases, the pointed PHP code may change (php file upload or overwrite) without the admin allowing it knowing. Don't allow "use_smarty_php_tags" {php}source{/php} unless you understand what you are doing and you have hardened your PHP infrastructure.
Pierre M.
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 6:19 pm
by RonnyK
Pierre,
which UDT of Nullig are you referring to. I didn't find one so quickly
Ronny
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 7:20 pm
by Pierre M.
Not Nullig's UDT. It's "Nullig's UDT solution" rather than "use_smarty_php_tags on" solution. If the code in maintained in a known UDT, it is more secure than if it came from an unmonitored file or content.
Pierre M.
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 7:27 pm
by RonnyK
Why is that one better than the one tractorboy mentioned. Or are you in general referring to a call through UDT?
Ronny
Re: How to add php code in a page ?
Posted: Wed Aug 29, 2007 7:43 pm
by Pierre M.
I'm not a PHP security expert, but comparing the two, I think the code in the included file may be less monitored than the code in a UDT (whose changes are logged). And the UDT in in the database. The included file may be more easyly overwritten.
I just wanted to stress that people who wide open their systems with "use_smarty_php_tags" must know what they are doing.
Pierre M.
Re: How to add php code in a page ?
Posted: Tue Sep 11, 2007 10:47 am
by tractorboy

Flattered !
Where security is a concern the UDT could be improved so that it only includes files from a directory that is not accessble to the web server, so that the files cannot be overwritten by upload exploits. I guess you'd also need to parse the parameter to make sure it's just a file name with no path.
Re: How to add php code in a page ?
Posted: Tue Sep 11, 2007 4:59 pm
by cyberman
Thanks for your note - added this.