john123456 Posted June 3, 2011 Share Posted June 3, 2011 Hi php legends, Please help me......... I am creating my own site with the help of php. I want to create a download link. The users can download from that. But they should not get the url by right clicking on the link. The url should not be updated on the address bar because they will get the url from address bar. Kindly help me with the corresponding php script. Thanks in advance John Quote Link to comment https://forums.phpfreaks.com/topic/238296-users-can-download-from-my-site-but-they-shouldnt-be-able-to-get-the-url/ Share on other sites More sharing options...
dougjohnson Posted June 3, 2011 Share Posted June 3, 2011 This works for me: $path = "/path/to/file/on/server/file.zip"; $mm_type="application/x-zip-compressed"; // modify accordingly to the file type of $path header("Content-Description: File Transfer"); header("Content-Type: " . $mm_type); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Transfer-Encoding: binary'); header("Expires: 0"); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-Length: " . (string)(filesize($path)) ); header("Cache-Control: private"); readfile($path); // outputs the content of the file Quote Link to comment https://forums.phpfreaks.com/topic/238296-users-can-download-from-my-site-but-they-shouldnt-be-able-to-get-the-url/#findComment-1224620 Share on other sites More sharing options...
ignace Posted June 3, 2011 Share Posted June 3, 2011 @dougjohnson how does that answer his question on shouldn't be able to get the url Since you only provide him the code on how to download the file. @OP You can't hide the URL since the download client needs a location to read the file from. If you want to hide the URL to avoid people downloading from the direct link. You can create a token that lasts for one hour so that they need a valid token in order to dowload from it. Combine that with checking the IP-address of the download and the User-Agent and the chance becomes really small multiple people are downloading from one and the same URL. This isn't a 100% guarantee but about 99.8% give or take. Quote Link to comment https://forums.phpfreaks.com/topic/238296-users-can-download-from-my-site-but-they-shouldnt-be-able-to-get-the-url/#findComment-1224740 Share on other sites More sharing options...
revraz Posted June 5, 2011 Share Posted June 5, 2011 You could store the URL in a database, so the link actually points to the DB and not the actual file. Quote Link to comment https://forums.phpfreaks.com/topic/238296-users-can-download-from-my-site-but-they-shouldnt-be-able-to-get-the-url/#findComment-1225316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.