php code in Resources

php code in Resources

- Bill Burgos の投稿
返信数: 6
Greetings all,

I am wondering if one can enter php code in the HTML choice of Resources?

I have tried, but it seems to not parse at all.

Thanks in advance.

Bill
Bill Burgos への返信

Re: php code in Resources

- Martin Dougiamas の投稿
画像 Core developers 画像 Documentation writers 画像 Moodle HQ 画像 Particularly helpful Moodlers 画像 Plugin developers 画像 Testers
No, not possible ... that would be a massive security risk.

Perhaps that might be an optional feature to add sometime, though, for admins only, perhaps.
Martin Dougiamas への返信

Re: php code in Resources

- Bill Burgos の投稿
Martin,

Thanks for your reply.

I asked the question because I am writing material in html and php format. Right now I am using resource to link to the 'web page' option. The problem is that when displayed, anyone can open the nested frame in a new window which allows anyone to see the material and/or bookmark to the same. This could allow anyone outside of the course to view the material.

I thought that if I can include the php code within the resource module, the material would only be viewed within the platform.

Any ideas on how to protect the material within the Moodle platform and use php.... and keep it safe?

Thanks in advance.

Bill
Bill Burgos への返信

Re: php code in Resources

- Greg Barnett の投稿
in your php, include the moodle config file. use moodle functions such as isadmin, isguest, etc to validate users.

I do variations on the above for lots of pages. I find that using my makeclass utility (found in contrib, which you can get from moodle cvs) makes integrating moodle code with existing code much easier.
Greg Barnett への返信

Re: php code in Resources

- Martin Dougiamas の投稿
画像 Core developers 画像 Documentation writers 画像 Moodle HQ 画像 Particularly helpful Moodlers 画像 Plugin developers 画像 Testers
Yep, what Greg said.

To be more specific, add:
      require("location/moodle/config.php");
at the top of each of your PHP scripts, and then:
      require_login(); 
followed by your code. All this does is check that the person is logged in to the server - it does not do a check for enrolment in a course (sadly this isn't currently possible in normal resources).

Another way is to use the "Program" resource type. This passes url, username, password etc to the external resource (as part of the URL, ie GET). You can get more details on the format by looking in mod/resource/view.php (must document it some day). The Program type probably needs some work to pass information in a less convoluted way, but it should be usable enough.
Martin Dougiamas への返信

Re: php code in Resources

- Greg Barnett の投稿