« Project home page

phpSQLiteCMS Forum

Back to the forum index
Linear

PHP Code in Generated pages (General)

by Paul @, Friday, October 16, 2009, 02:58 (328 days ago)

Hi, this has not been explained in previous requests. In Version 2.0.beta.1, I want to embed PHP code in CMS pages. Example...

<h1>My Page</h1>
<p>Here is a paragraph</p>
<p>Here is a paragraph with some PHP...
<?php echo 'PHP Stuff Here'; ?>
</p>

I can add this code in the page editor, but the PHP is stripped out when the page is displayed; instead, empty space is rendered by Firefox (confirmed via 'View Page Source' a blank line tag shows instead. Is this a config in phpsqlitecms or is it a PHP config issue?

Note that adding PHP code as above will display if added to Templates, but not in CMS pages, so I suspect the issue is somewhere in phpsqlitecms.

Please clarify.

PHP Code in Generated pages

by BillB, Friday, October 16, 2009, 19:07 (328 days ago) @ Paul

Many CMS developers discourage PHP embedded within the HTML coming out of the editor. It's dangerous and the developers know that if something goes wrong, people will complain to them about allowing PHP in HTML. So they avoid it.

Unless your site is a hacking site and not a production site, it is far more secure to put PHP code in template where it belongs.

However, I've done a couple of hacking sites with embedded PHP. The *relatively* easy way to do is just to allow the editor to mangle the PHP code and then take the "tidy" code, that is,

<pre>
&lt? echo 'hello world'; ?&gt
</pre>

and apply the transforms,

<pre>
content = content.replace(/&lt;\?/gi, "<?");
content = content.replace(/\?&gt;/gi, "?>");
</pre>

restoring the PHP tag to

<pre>
<?php echo 'hello world'; ?>
</pre>

The fixup code above is Javascript, but the same thing can be done with PHP.

There are numerous threads on using the code cleanup module at the TinyMCE forum.
http://tinymce.moxiecode.com/punbb/viewtopic.php?id=3460

You will still have problems with escapes like,

<pre>
<?php echo 'I\'m saying hello world' ?>
</pre>

The whole issue of embedded PHP is a big pain and probably not worth the time and effort. phpSqliteCMS has good support for templates so it is probably quicker and easier to create a new template.

- Bill B

P.S. about PHP Code in Generated pages

by BillB, Friday, October 16, 2009, 20:19 (328 days ago) @ BillB

I just noticed that the built in editor is not mangling PHP tags. So, apparently the "tidy" function is being executed before the HTML content of the page is evaluated. In other words, you would have to explicitly deactivate the safeguards the developers put into the system to get the PHP tags to execute.

Doesn't sound like a good idea to me.

Bill B

PHP Code in Generated pages

by Alex @, Saturday, October 17, 2009, 10:21 (327 days ago) @ Paul

Hi Paul,

what you could do is using the [function:...] feature.

Alex

RSS Feed of thread
192 Postings in 89 Threads, 63 registered users, 6 users online (0 registered, 6 guests)
Forum time: 2010-09-09, 15:28
RSS Postings  RSS Threads | Contact
powered by my little forum