Page 1 of 1

run PHP code in posts

Posted: Sat Apr 21, 2007 8:26 pm
by Mgccl
I want some PHP code running in my posts.
I have searched around the forum and i don't see anyone mention how to do so, in the FAQ it only show us how to embed PHP code in the template.
Is there are configuration I can do to make it run PHP codes?

Re: run PHP code in posts

Posted: Sun Apr 22, 2007 12:41 pm
by garvinhicking

You cannot embed PHP code in entries because of security considerations.

You have two options:

1. Create a s9y plugin. The API is not that hard, and its the cleanest integration. See the docs on for api docs.

2. Use the smartymarkup plugin to put Smarty markup code in entries. If you turn of smarty security - put a file in your template directory and set

Code: Select all

$serendipity['smarty']->security = false;

- then you can also use {php} smarty markup within your entries.

Best regards,

Posted: Sat Apr 28, 2007 11:52 am
by baden32
I found this interesting post, unfortunately, I cannot understand how to set it up in my blog.

I installed Markup: Smarty Parsing plugin, add a file in the my "competition" template folder and added the following in the HTML code of my post: {php}echo 'hello';{php}.

When the post is diplay, I see echo 'hello'; instead of just hello! What am I doing wrong?

Thank you for your help.

Posted: Sat Apr 28, 2007 12:00 pm
by baden32
I found why the code was not exectuted: the closing tag was wrong: {/php} instead of {php}.

However, my goal is to get within the post a parameter comming from the URL: index.php?/

I insert the following code: {php}$i=32;echo $i; echo $_GET['vid'];{/php} but only the output if echo $i, the second command is not displayed.

Posted: Sun Apr 29, 2007 1:33 pm
by garvinhicking

Maybe you can add:

Code: Select all


to see if $_GET is really there? Depending on your PHP Version you might need to use $HTTP_GET_VARS instead...?


Posted: Mon Apr 30, 2007 5:01 pm
by baden32
I found the problem:

Instead of writing my URL like index.php?/, I need to use


The parameters I need to get should be placed immediately after the "?".

Problem is solved thanks for your help.