When I first tried Moodle, I've been impressed by so many features so easely to use. Among those features I've appreciated the simple integration with existing material, such as web link or web pages by the use of resources: this widen the possibility of using external content managent system or material from other HTML editors.
On the counterpart, when linking external web pages outside Moodle, anyone knowing the direct link could view the resource: there are several situations where accessing resource pages should not be allowed. So i I've adapted some code trying to solve the problem: attached youll'find two .php files you can download and test. Follow the instruction below, test them and, of course, any feedback will be greatly appreciated. If anyone has alredy built somethng like this, we could merge the solution.
Assumption: a folder containing external resources must be created in the same web server where your Moodle is running. The folder can be any name and can be anywhere, also outside the Moodle's application folder. If you place the folder inside the Moodle's folders structure, please choose a unique name to avoid overwriting and conflicts. For the purpose of the following instruction, the external resource folder will be called "protected"
- make a folder name "protected". Copy the two attached .php files.
- inside the "protected" folder, create one or more resource folder, such as "course1", "course2" and so on, so if needed you can subdivide web link resources belonging to different courses.
- edit the protect.php file and change the path to your Moodle's config.php. The path must be absolute, not http path.
- inside "coursex" folders, copy the file rsp-dist.php and rename it rsp.php.
- edit the rsp.php file: if you want to protect a specific course id, then modify the $myid variable accordingly in rsp.php. This is usefull when a course is password protetcted. Otherwise left $myid == -1, this way all authenticathed site user can directly access the resource. To obtain the course id, simply check the id value in the URL when you click on a course name link.
- Before uploading your resource material, if your external resource page has the .htm or .html extension, change it to .php. If you do this inside an editor such as Dreamweaver, links in other pages will be changed accordingly. Do this for all your pages you want to protect.
- At the very first line of each page to protect, add this instruction: <?PHP require_once("rsp.php") ?>. Check twice the path to rsp.php and change accordingly. If you have subfolders inside "coursex", the path should be "../rsp.php".
- Upload the external resources in the right folder, such as "course1".
- Try to acces the resources pointing directly to a resource page. The scenarios should be:
- $myid == -1. This is the default case. Any authenticathed user will be allowed to directly see the resource after login
- $myid == a course id. In this case, if the course is not password protected, after login the user will be redirected to the enrollment page. If the course is password protected the user, after login, will be redirected to the page where the course password can be typed. In both cases if the user is already enrolled to the course, the resource will be displayed.