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!