run PHP code in posts

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Mgccl
Posts: 2
Joined: Sat Apr 21, 2007 2:05 am

run PHP code in posts

Post 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?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: run PHP code in posts

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
baden32
Regular
Posts: 18
Joined: Mon Feb 12, 2007 3:48 pm

Post 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.
baden32
Regular
Posts: 18
Joined: Mon Feb 12, 2007 3:48 pm

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
baden32
Regular
Posts: 18
Joined: Mon Feb 12, 2007 3:48 pm

Post 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.
Post Reply