PHP block

PHP block

by Garrett Murphy -
Number of replies: 8

Okay, I can see a number of people have asked about the creation of a Block that enables PHP scripting, and everybody refers them to follow the How-To for creating a Block...but I have yet to see anything that shows scripting to enable PHP script.

Does anybody have a ready-made block to enable PHP script that he/she would be willing to share?

Average of ratings: -
In reply to Garrett Murphy

Re: PHP block

by Genner Cerna -
Im also in search of the said block, hope this will be available soon... thanks
In reply to Garrett Murphy

Re: PHP block

by Darren Smith -
Another 'Me Too' post smile

You may want to ask in the general developers forum if you get no joy here.

Darren
In reply to Garrett Murphy

Re: PHP block

by Matt Crosslin -
Is everybody looking for a block, like the html block, that allows a teacher of a course to enter whatever php script they want, and it works?

The problem with that is, the script would have to be stored in database.  Once you pull it out of the database, it would be stuck inside of a function in the block.  You really can't run a random PHP script, queried out of a database, inside of the function that is written for the block.  It really goes down to how the block function is designed in Moodle:

$this->content->text = ' (content here) ';

I don't know if PHP is designed to allow something in the (content here) to run php scripts.  But I can check.
In reply to Matt Crosslin

Re: PHP block

by Matt Crosslin -
Yeah, I just checked it out.  PHP doesn't run a script once it is pulled out of a database.  It just inserts it in the page as text.  If you put <?php ?> around it, it just hides it from the browser, but doesn't run the script.  I don't think this kindof block is going to be possible.  Unless someone knows a way aroung this.
In reply to Matt Crosslin

Re: PHP block

by Jan Dierckx -

You can use PHP's eval function to execute a string pulled from a database, but giving users (even teachers) access to PHP directly, poses some real security threats.

I guess the best workaround is what has been suggested before: the blocks manual is a great piece of documentation. If you know some php (as must be the case for anyone who is looking for a way to add php scripting to a block) it only takes a small extra effort to implement your php script into it's own block

In reply to Jan Dierckx

Re: PHP block

by Paul Andrews -
Give teachers the power to run PHP?

You know Moodle has built in commands that allow folks with PHP to access the DB without knowing the user/passwords (I used them in the Livestats block).

It would be possible for someone to make a block that contained SQL that dropped the enitre Moodle DB - this would not be good.

I'd say leave this one be - it would be asking for trouble!

tongueout
In reply to Paul Andrews

Re: PHP block

by Matt Crosslin -

I think it would depend on your teachers, really.  I've seen experienced, advanced PHP developers accidentally drop entire databases before, so let's not think that only some neophyte teacher would do that.

Anytime you give that kind of access to ANYONE, you give up some security (even the webmaster can mess up).  I can use th html block and write code that will destroy the database.  All you needs is some JavaScript and an iframe.

Even with php enabled, you would still need to know the name of the database to do anything with it.  Or the name of the Moodle function that accesses the database.  By the time that you would find someone with ability to do all that, you've pretty much found someone who can do it even without a PHP block.

Something like this could be useful for the right purposes, and it could be given to those with the know-how to use it correctly.  I say go for it!