Need help with php referrel URL.

Hello, i need help argently. Can anyone tell me a php script which can download a file if only referred from a certain url? A script which does not work if it is accessed directly and not work if referred from any other URL.

For example i had this www.domain.com and i have a zip file for people to download. And I have a “Download now” button in www.domain.com. For example the zip file was www.domain2.com/thezip.zip. i want a script which makes the zip file download only if a user click the “Download now” button (or any button) from the www.domain.com. And not to download if the user copies and paste it in the browser or a downloading software.

So its something like this. www.domail.com has a button which say maybe “Download Now” and when the user clicks that button it sends the user this scripts maybe www.domain2.com/thescript.php and this script checks if the user is being send from www.domain.com or not. If the user is being send by www.domain.com the script lets the user to download a file. If not, maybe the page dies or something.

Well, first when programmers place a link on the page, it is viewable in the source code.
So, you do NOT want to place a simple link in a button. The best way is to do this inside of PHP.
The reason is that PHP is SERVER-SIDE and can not be seen by any user on the client or browser side.
So, there are many ways to do this, but simple is always best. Add a form to your page with a submit button
that is set for download. On the form, call a PHP file on the server, let’s call it Download.php. In that file,
you would handle all of the buttons on the form. Call the download button, let’s say butt_download.
In your PHP form code do something like the following:

file: Download.php (only the download button part…)
[php]

<?PHP // Handle Download Button Pressed... if(isset($_POST['butt_download'])) { $filename="download.zip"; // This could be pulled from the form page or however... header("Content-disposition: attachment;filename=$filename"); readfile($filename); } [/php] ***Note: You should alter your downloadable files so they are read-only on the server. Also, you can save them inside a hidden folder so the average hacker would never see then. This is done on your server, right-click on your folder and alter the options there. This way the file is hidden, but, can still be used by your PHP code. *** Good luck, hope this helps...
Sponsor our Newsletter | Privacy Policy | Terms of Service