Protected Links

This add-on lets you encrypt/secure download links, restrict access to the files and also display some useful statistics. It consists of module and fieldtype.

Features

Installation

Place protected_links directory with all files inside /system/expressionengine/third_party directory. Then go to 'Modules' section in your Control Panel and enable both module and field type.

Create link from Control Panel

While you are able to generate links 'on the fly' in your templates, you can also generate them from module Control Panel. That way, you'll be able to add some custom access restrictions and then use links as fieldtype values or pass it to users manually.

To generate the link, go to Module section of your CP, select Protected Links and then Generate Link tab. There, fill in following fields:

If you use local folder, make sure you specify full path to file - not relative to your webserver root. It is generally recommended to place the files outside of web root.

CloudFront integration

Normally, Protected Links passes files though your server to make sure the original location is not exposed. However, if you are CloudFront user, you can take advantage of their signed URLs and have the authenticated visitors redirected to CloudFront signed URL, which is created for his IP and is valid for 24 hours. In the settings, fill in CloudFront Key ID and Secret Key fields. Make sure you have distributions created (with 'Restrict Viewer Access' set to 'Yes' and 'Forward Query Strings' to 'No', other settings are up to you). If you create protected link for a location that does not have distribution, the file will be served though your server just like for 's3' storage. When creating protected link, you will be entering data for the file on S3, CloudFront URL will be created automatically.

Display link using fieldtype

After you installed the fieldtype, you can create new custom fields of type "Protected Link". The field is select dropdown containing pre-generated links.

If you add the "Protected Link" field to list of your fields, you then can select its value for each channel entry and then display it using your templates.

If your field is named, say, "dl_link", you can use following tags:
{dl_link} — pre-formatted download link
{dl_link:link} — only the actual link, to be used inside <a href="">
{dl_link:total_downloads} — total number of downloads for the given link {dl_link:filename} — file name {dl_link:title} — link title {dl_link:description} — link description

Display link by link ID

You can display the links you generated in Control Panel using their ID (and so outside channel entries loop). The link ID can be found on Links tab of module CP.

{exp:protected_links:display link_id='32'}

Display all files user can access

You can display all files that user is permitted to access/download using {exp:protected_links:files} tag.

<ul>
{exp:protected_links:files}
<li><a href="{link}">{title}</a> ({filename})</li>
{/exp:protected_links:files}
</ul>

Parameters:

Variables:

Display all files user downloaded previously

You can create "my downloads" section that would display all files user has downloaded previously using {exp:protected_links:my_downloads} tag.

<ul>
{exp:protected_links:my_downloads}
<li><a href="{link}">{title}</a> ({times_downloaded}) Last download" {download_date format="%Y-%m-%d"}</li>
{/exp:protected_links:my_downloads}
</ul>

Parameters:

Variables:

Generate and display links in front-end

You need to check yourself based on your own conditions whether to display this tag and give user access to file. It does not make any checks by itself.

{exp:protected_links:generate url="http://www.domain.com/path/to/file.zip" ip_lock="yes" guest_access="yes" title="Get the file!"}

Tag
{exp:protected_links:generate}

Parameters:

View downloads statistics

In the module's control panel, you'll see the tabs named 'Files', 'Links' and 'Members'. They are intended for displaying download statistics grouped by file, link and member respectively.

The File tab shows all the files you are offering for download. If you click file URL you'll see the detailed stats for each file. From there, you can also view detailed link stats or proceed to link editing.

The Link tab shows all the links you generated using CP. If does not show any frontend-generated links. You can edit the link or view detailed link stats.

The Members tab shows download statistics grouped my member - who downloaded what.

Downloads by admins are not recorded and so not displayed.

How to secure the files storage

If you are storing the files on your web server, they still can be downloaded directly if people know the 'real' URL. If you're very strict about security, you should place the files outside of web root to secure the files location.

Create a folder named, say, 'files' next to your document root folder (usually 'public_html' or 'htdocs'). Place your files in that folder. The folder is not accessible via HTTP, so people can never access the files directly. Note that in this case you can use only 'local path' storage for Protected Links and provide the full path.

If you generate links in the template, then your code can look like this:

{exp:protected_links:generate url="/full/path/to/upload/directory/{files}{filename}.{extension}{/files}" storage="local"}

Top of page