This question already has an answer here:
I have provided a straight download link in my site as below.
<a href="myfile.pdf">Download here</a>
This file is accessible to every one. But i want to restrict this based on logged in users.
Say an user have an active session / cookie upon successful login as below.
$_SESSION['login'] = 1 or $_COOKIE['login'] = 1
even if set following condition, people can manually type http://web.com/myfile.pdf and able to download the file...
if($_SESSION['login']===1 && $_COOKIE['login']===1){
echo '<a href="myfile.pdf">Download here</a>';
}
Other Anonymous users should not be able to access the file.
</div>