Home > CMS Tutorial > WordPress > How to set up user login in wordpress to download files

How to set up user login in wordpress to download files

Release: 2019-07-16 11:00:03
Original
3916 people have browsed it

How to set up user login in wordpress to download files

Users must log in to download files:

Purpose: To protect downloaded files from being downloaded by non-registered users.
1. Determine whether you are a registered user
2. If you are a registered user, download the file.
Implementation method:
Cannot use redirect method:
echo "<script>window.location='".$download_addr."';</script>";
Using this method, the user can see the address of the downloaded file from the address bar, and it is possible to directly use the address to download and bypass the restrictions of registered users.
A method found on the Internet is as follows:
Create a download folder outside the web publishing directory on the server, and put the files that need to be downloaded into the folder.
The php program uses streaming mode to download files:
header ("Content-Disposition:attachment;filename=$your_download_filename");
header ("Content-Length:".filesize($path_of_your_download_file));
header ("Content-Type:application/octet-stream");
readfile ($path_of_your_download_file);
3. If you are not a registered user, the registration page will be displayed.

For more wordpress related technical articles, please visit the wordpress tutorial column to learn!

The above is the detailed content of How to set up user login in wordpress to download files. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template