Jump to content

run php scripts within process-wire CMS


werner
 Share

Recommended Posts

I wrote some special php scripts to communicate with a sql data base (readsql.php, writesql.php, ...) and now I would like to call the scripts between normal html commands. I tried with the readsql.php script like this:  

<?php require("readsql.php"); ?>

but only this text code was shown on the fronted.

In which directory should I move this readsql.php file to locate it without a path in the require call ?

Or  is there a better way to handle site content that should perform calculations?

Edited by owzim
fixed font style mish mash, added code block
Link to comment
Share on other sites

23 hours ago, LostKobrakai said:

Do you mean a external php file or literally the string "echo …"? The first one you'd include/require and the latter one can be executed by eval. But keep in mind that any dynamic php code can be a security issue if not handled with care.

 

Link to comment
Share on other sites

On a normal page with html code created by the processwire cms I would like to execute an external developed php file.  If this page is called by a nav bar, then the php file should be loaded and executed. On a standard html page it could look like:

<hr>

<p>

<?php

require("readsql.php");

?>

</p>

<hr>  

If I type this code on the backend, the commands are interpreted as pur text and they are not executed on the fronted. 

Link to comment
Share on other sites

2 hours ago, werner said:

If I type this code on the backend, the commands are interpreted as pur text and they are not executed on the fronted. 

If you enter PHP code into an inputfield in Page Edit you would have to eval() it in your template in order for it to execute. But the idea of entering PHP code into Page Edit is really not good. If you want to execute a PHP block within some HTML coming from Page Edit then use the Hanna Code module.

  • Like 7
Link to comment
Share on other sites

Hello @werner, welcome to the ProcessWire forum.

The fact that you're fiddling with sql suggests that you are an advanced user, so why inject PHP directly into a text field? That's not what it's for. If you really want to execute individual PHP code on each page, you might want to use something like Hanna Code.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...