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
Hi!

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 www.s9y.org for api docs.

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

Code: Select all

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


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

Best regards,
Garvin

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 config.inc.php 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.
Joel.

Posted: Sat Apr 28, 2007 12:00 pm
by baden32
CORRECTED:
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?/2.my-post.html&vid=22.

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
Hi!

Maybe you can add:

Code: Select all

print_r($GLOBALS);


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

Regards,
Garvin

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

Instead of writing my URL like index.php?/2.my-post.html&vid=22, I need to use

index.php?vid=22&/2.my-post.html

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

Problem is solved thanks for your help.