https://www.icyphoenix.com/viewtopic.php?f=4&t=2411&p=50535#p50535
-----------------------------------
archan
Sun 31 Oct, 2010 15:22

Re: SECURITY - How To Prevent Hotlinking With PHP
-----------------------------------
Hotlinking can also be protected by assigning a session variable. When viewer comes to the download page that page will assign a session variable which enable php attachment download. But if viewer directly enter a download link, i.e. if session variable is not set that link will be redirected to the download page.
[u]Download page:[/u]
[code linenumbers=false]<?php
session_start();
$_SESSION['download']='ok';
?>[/code]
[u]Attachment download page:[/u]
[code linenumbers=false]<?php
session_start();
if($_SESSION['download']!=='ok'){
$redirect='index.html'; //URL of the page where you want to redirect.
header("Location: $redirect");
exit;}
//Attachment download code.
?>[/code]
For more information: [url=http://www.ramui.com/articles/hotlink-protected-php-download-script.html]Hotlink protected PHP download script


