Forums / General Questions / PHP inside ezpages

PHP inside ezpages

Views: 54,058

Results 1 to 20 of 114
01 Jun 2006, 13:51
#1
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

PHP inside ezpages

MODERATOR COMMENT: Adding eval() to arbitrarily execute random PHP or other code in the manner suggested here opens your site up to security risks.
USE AT YOUR OWN RISK.

Not a Question, but I didn't know where else to post this.

I posted this in the infopages thread a while back. I have updated it to work with ezpages in 1.3.0

To allow PHP code to run inside a "page".

copy includes/templates/template_default/templates/tpl_page_default.php to includes/templates/your template/templates/

Then edit the new copy as such find between "<div></div>"

echo $var_pageDetails->fields['pages_html_text'];

and replace with:

$titlecheck=substr($var_pageDetails->fields[pages_title],0,9);
if ($titlecheck=="allowcode"){
eval(stripslashes($var_pageDetails->fields['pages_html_text']));}
else{echo $var_pageDetails->fields['pages_html_text']; }

Change "allocode" to whatever name you want your php code ezpages to have, or add more names or remove the if alltogether if you want. (dont forget to change ,0,9 to ,0,x where x is the length of your "allowcode" replacement string.

I hope this is helpful. (I notice that someone else was looking to use include in infopages or ezpages, That's exactly what I am doing. Apparently That person didn't dig deep enough in the other thread, it was 30+ pages long.)

02 Jun 2006, 01:08
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
9

Re: PHP inside ezpages

Thanks for this Techbrat. It looks interesting and potentially relevant to something I am about to do.

02 Jun 2006, 03:06
#3
gerard avatar

gerard

Zen Follower

Join Date:
Oct 2005
Location:
Qld Australia
Posts:
124
Plugin Contributions:
0

Re: PHP inside ezpages

And to think that I was about to tackle that little nightmare and along comes the solution :thumbsup:

One question

dont forget to change ,0,9 to ,0,x where x is the length of your "allowcode" replacement string Can this point be clarified since I am only new to the whole php experience.

Thx Gerard :smile:

02 Jun 2006, 03:21
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP inside ezpages

There is something down the pike for this that we have been fooling with for EZ-Pages to allow for an includes/require ...

Ideas of how you forsee using this are helpful to hear ... :smile:

02 Jun 2006, 11:34
#5
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: PHP inside ezpages

Gerard:

And to think that I was about to tackle that little nightmare and along comes the solution :thumbsup:

One question "dont forget to change ,0,9 to ,0,x where x is the length of your 'allowcode' replacement string " Can this point be clarified since I am only new to the whole php experience.

Thx Gerard :smile:

I made it so that only certain page names will trigger this change. In case of the example it is allowcode. "allowcode" is 9 characters long. If I change that to "Form" then every form I create I could name Form1 or Form-1 or Form-Contact etc, then the forms will work. But you will need to change

$titlecheck=substr($var_pageDetails->fields[pages_title],0,9);
if ($titlecheck=="allowcode"){

to

$titlecheck=substr($var_pageDetails->fields[pages_title],0,4);
if ($titlecheck=="Form"){

Remember that "==" is a case sensitive evaluation.

I have used this to include dynamic content in an infopage (now ezpage), and to create a custom contact form with handler.

02 Jun 2006, 11:43
#6
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: PHP inside ezpages

I think I forgot to mention, With this setting, The ezpage with a title that begins with "allowcode", or "Form" in the second examle, will assume "<?" or one might say that PHP is already "on". If you want some HTML before your PHP code, start with "?>" Like

 
?>
<a href="http://www/zen-cart.com">Get Zenned</a>
<?
include ("some_great_file.php");
?>

otherwise, like this

include ("some_great_file.php");
?>
<a href="http://www/zen-cart.com">Get Zenned</a>
20 Jun 2006, 23:04
#7
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: PHP inside ezpages

MODERATOR COMMENT: Adding eval() to arbitrarily execute random PHP or other code in the manner suggested here opens your site up to security risks.
USE AT YOUR OWN RISK.

I definately needed this feature. Here's an even simpler version.

Replace this:

<div><?php echo $var_pageDetails->fields['pages_html_text']; ?></div>

with this:

<div><?php eval(stripslashes('?>' . $var_pageDetails->fields['pages_html_text'])); ?></div>

This way you don't have worry about php being 'on' in the ezpage - you can make the code of the page html with php inside it (a lot easier).

Tim

11 Oct 2006, 19:55
#8
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: PHP inside ezpages

brandtim:

I definately needed this feature. Here's an even simpler version. ... Tim

<div><?php eval(stripslashes('?>'.$var_pageDetails->fields['pages_html_text'])); ?></div>

Verified this works in 1.3.5

Thanks for the simplification Tim. I am starting to really appreciate the concatenation operator!

12 Oct 2006, 01:58
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
174

Re: PHP inside ezpages

Be sure to thoroughly understand the security risks associated with using the eval() function.

14 Nov 2006, 04:18
#10
rambo avatar

rambo

New Zenner

Join Date:
Jul 2006
Posts:
32
Plugin Contributions:
0

Re: PHP inside ezpages

I notice I can't input php with the default wysiwyg editor. It erases it and replaces it with a line break.

I'm wanting to replace ezpages with my own uploaded php pages to be wrapped by the site. Is there an easier way to do this than to have an include in the ezpage?

17 Nov 2006, 13:51
#11
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: PHP inside ezpages

rambo:

I notice I can't input php with the default wysiwyg editor. It erases it and replaces it with a line break.

I'm wanting to replace ezpages with my own uploaded php pages to be wrapped by the site. Is there an easier way to do this than to have an include in the ezpage?

Before I discovered the eval() function, we used inline frames to present our PHP pages in the old infopages module. Passing variables can get tricky, but it works.

17 Nov 2006, 20:40
#12
rambo avatar

rambo

New Zenner

Join Date:
Jul 2006
Posts:
32
Plugin Contributions:
0

Re: PHP inside ezpages

I'm good to use the eval function method. I just need to know how I can place php code into a page via a wysiwyg editor in ezpages. Like I said, the default embeded wysiwig is erasing my code. How are you guys doing this?

19 Nov 2006, 21:25
#13
wils avatar

wils

Zen Follower

Join Date:
Apr 2006
Location:
Göteborg
Posts:
124
Plugin Contributions:
0

Re: PHP inside ezpages

$titlecheck=substr($var_pageDetails->fields[pages_title],0,9);
if ($titlecheck=="allowcode"){
eval(stripslashes($var_pageDetails->fields['pages_html_text']));}
else{echo $var_pageDetails->fields['pages_html_text']; }

Change "allocode" to whatever name you want your php code ezpages to have, or add more names or remove the if alltogether if you want. (dont forget to change ,0,9 to ,0,x where x is the length of your "allowcode" replacement string. This way of using php in EZ-pages works in 1.3.6, but if used as an EZ-link and the "allowcode" check is used, how do you avoid the actual link to include "allowcode"?

Or do you grab the EZ-page content directly from the database into another page (such as an info page) somehow? If so - how?

My use is to store, say, seasonal texts (spring, summer, winter etc) as EZ-pages or define pages, and then in another EZ-page, or the main page, or in a category text reference the predefined seasonal EZ-page/define page -> an easy way to shift "templates" stored as EZ-pages. I see a huge potential for using ez-pages as "includes" on other pages (such as the main page, category descriptions, in the blank_sidebox) etc.

10 Jan 2007, 09:34
#14
dantheman avatar

dantheman

New Zenner

Join Date:
May 2005
Location:
Toronto, Ontario, Canada
Posts:
41
Plugin Contributions:
0

Re: PHP inside ezpages

This may be a solution for those using built-in WYSIWYG editors to edit PHP code. Unforutunately, both HTMLArea and TinyMCE WILL remove or damage PHP code.

The good new is that FCKEditor "knows" about PHP and leaves it alone. You can grab it from Zen Cart downloads section here: http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_41&products_id=268. It should work "right out of the box". If, however, you get an updated version from http://www.fckeditor.net/, you'll need to edit a configuration file - specifically add or uncomment one line in fckconfig.js

FCKConfig.ProtectedSource.Add( /<\?[\s\S]*?\?>/g ) ;

The version from the downloads section already has this line uncommented, so you don't need to do it.

Note: you'll only see the PHP code in "Source" mode, it will not be visible in normal mode.

Feedback is welcome!

Dan G.

Notebook Solutions Inc.

http://www.notebooksolutions.ca

13 Jan 2007, 03:26
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP inside ezpages

I can see it is coded to do this ... but I am having a user moment here ... and not getting it to actually execute the php code ... so what's the trick? :unsure:

03 May 2007, 12:15
#16
picci avatar

picci

Zen Follower

Join Date:
Feb 2006
Posts:
125
Plugin Contributions:
0

Re: PHP inside ezpages

I am using ZC 1.3.7

I have tried both methods described in this thread and can not get it to output PHP code.

I am trying to troubleshoot my problem. Does this method work in ZC 1.3.7 ?

Thanks for your support,

Pic

03 May 2007, 12:26
#17
picci avatar

picci

Zen Follower

Join Date:
Feb 2006
Posts:
125
Plugin Contributions:
0

Re: PHP inside ezpages

Sorry, I had bad PHP in my test, ignore previous post asking for troubleshooting help.

The both methods work fine in ZC 1.3.7

What are the security issues when using this code?

Thanks for your support,

Pic

23 May 2007, 14:20
#18
cmilesjr avatar

cmilesjr

New Zenner

Join Date:
May 2007
Posts:
4
Plugin Contributions:
0

Re: PHP inside ezpages

Hello All,

I didn't have any problem putting the .php code into my ezpage but i do have a problem with the page opening sub-pages.

What i'm trying to do is use a PHP link manager code to manage links. The code works great until you click on a catagory to see the links inside that catagory. I'm thinking it has something to do with dynamic link page numbers since the linked page info is looking for /resources.php?cid=1831 and Zen uses /index.php?main_page=page&id=3&chapter=1

is there anyway to get around that other than installing USEO? which looks great, but seems to have some problems from all the messages and issues i've read.

You can take a look for yourself at: http://smilesdiscounts.com/index.php?main_page=page&id=3&chapter=1

Thanks in advance!

Cornell

28 May 2007, 17:45
#19
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: PHP inside ezpages

Use the simplified version given by brandtim 20th June 2006, 07:04 PM.

<?php eval(stripslashes('?>' . $var_pageDetails->fields['pages_html_text'])); ?>

It's simply better. If for some reason, that just won't work for you, choose a word that is keyword rich in place of "allowcode". Just remember to replace the "9" in "],0,9)" with the length of your keyword. Then it won't (or shouldn't) matter if it shows up in the link.

You could also do multiple title checks, but that requires a hard edit for every page where you want to allow the code. Take out the substring part, and test the full string ``` if ($titlecheck=="allowcode" || $titlecheck=="Some Page Title" || $titlecheck=="Another Page"){...



> **Wils:**
>
> ```
$titlecheck=substr($var_pageDetails->fields[pages_title],0,9);
if ($titlecheck=="allowcode"){
eval(stripslashes($var_pageDetails->fields['pages_html_text']));}
else{echo $var_pageDetails->fields['pages_html_text']; }

This way of using php in EZ-pages works in 1.3.6, but if used as an EZ-link and the "allowcode" check is used, how do you avoid the actual link to include "allowcode"?

01 Jun 2007, 01:33
#20
doodlebuckets avatar

doodlebuckets

Totally Zenned

Join Date:
Jul 2005
Posts:
497
Plugin Contributions:
0

Re: PHP inside ezpages

OK, I am a bit slow and I don't understand how EZPages are generated. I have this code that I want to put on http://www.giftsbearsetc.com/store/index.php?main_page=page&id=1&chapter=0 via EZPages.

**<?php /*<--- BEGIN MY LINK HELPER CODE --->

Making modifications to this code can cause your links page to stop working. Please only make modifications where modifications are allowed. Being that this is a free service, we do not have the resources to help you debug any changes you may have made. If you do run into problems with this code, log into your account and download the original again.

*/ $OnCat = @$_GET["cid"];

if ($OnCat == "") {$OnCat = "0";} //Set to Main Directory Page

//You may name your links page anything you want. But for your links page to work correctly //you must provide us with the name of your links page (without the '.php' extension). $PageName = "resources"; // change this value to match your [PageName].php links page

//You may modify the following variable to change how many columns your main directory displays. //By default this value is set to show 2 columns, but you may show as few as 1 column or //as many as 4. Valid values (1,2,3,4) $DirectoryCols = 2; // change this value to adjust how many columns your main directory page displays

//You may modify the following variable to change how many columns your sub category directory pages display. //By default this value is set to show 2 columns, but you may show as few as 1 column or //as many as 4. Valid values (1,2,3,4) $SubCategoryCols = 2; // change this value to adjust how many columns your sub category pages display

//You may modify the following variable to display your links on a single page instead of //directory style. This is a convenient way to display your links if you have fewer than 40. $ShowAsSinglePage = 0; // change this value to 1 if you want a single page, or 0 for directory

$file = file("http://www.mylinkhelper.com/bin/phpdynfetch.asp?id=E65D16FF-A31E-4886-B052-9F52754E9A93&pagename=".$PageName."&cid=".$OnCat."&dircols=".$DirectoryCols."&subcols=".$SubCategoryCols."&single=".$ShowAsSinglePage);

if ($OnCat == "0") { //This value is the title for your main directory page and can be modified $sTitle = "Gifts Bears Etc."; $GetLinks = $file[0]; } else { $iPos = strpos($file[0], "|"); $sTitle = substr($file[0],0,$iPos); $GetLinks = substr($file[0],$iPos + 1,strlen($file[0])); } //<--- END MY LINK HELPER CODE ---> ?>

<!-- Place the following code into the location of your webpage template that you want your directory to be displayed, it will assume the link syles and sizes you have defined in your stylesheet. Also, don't forget to use the "sTitle" variable to customize the page! Please delete this comment when you implement your links directory. --> <title><?=$sTitle;?></title> <?=$GetLinks;?>**

This will display a links page. What do I do? I need specific instructions or I will fail for sure! Thanks...