joshedgar Posted August 17, 2007 Share Posted August 17, 2007 Hi guys, Does anyone know how to make a PHP script to generate temporary download links that expire after 10 minutes? And the temp link is generated at a PHP page which after 10 seconds redirects to their requested download? I can use PHP and Htaccess for this. This is what I want: The user wants to download a file. So the link goes to say: http://www.my-website.com/download.php?file=video.mp4 Then at that script, I want it to wait 10 seconds while they are looking at an advertisement, and then during that ten seconds, it should generate a random MD5 code, such as: 782d1a1a7a0a34c39995e1fa95efdbf5 It then passes this to a temporary download link on my server: http://www.my-website.com/download/782d1a1a7a0a34c39995e1fa95efdbf5/videos/video.mp4 Which is a cover-up for the REAL file URL, which is: http://www.my-website.com/files/videos/video.mp4 However, after about 10 minutes that temporary link expires and they have to go back to download.php for it to generate them a new code, if they want to download the file again. E.g. I want to protect my files against leeching with using my own script, without using Lix.in or a Frame or anything. Is there a way to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/ Share on other sites More sharing options...
joshedgar Posted August 17, 2007 Author Share Posted August 17, 2007 Anybody know? Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326601 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 have a MySQL database that have 3 fields file, hash, timestamp if the timestamp is greater than the time+(10*60*60) then delete the records now on a php page have the link something like ?file=782d1a1a7a0a34c39995e1fa95efdbf5 Now the 782d1a1a7a0a34c39995e1fa95efdbf5 is NOT the filename hash its something like md5(time().$filename) this is stored in the database under hash and the file name in the file field.. now when someone clicks the link ?file=782d1a1a7a0a34c39995e1fa95efdbf5 look up in the database to find hash=$_GET['file'], and pull the filename now use readfile to pull that data, search form for forced downloads i hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326615 Share on other sites More sharing options...
joshedgar Posted August 17, 2007 Author Share Posted August 17, 2007 I think I understand, but, I'd rather just keep it simple like having my links on the page be "download.php?file=videos/video.mp4". My latest attempt was doing md5(rand,1) or something like that, I read it in a book. Then I was going to do some stuff in .htaccess to make that work but I realized that wouldn't terminate the links properly. Basically what I want to do is something like this: http://tanksoftware.com/tutes/leechprotection.html But I don't understand all that, or how I'm going to start the functions properly with the current $_GET variables i have. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326619 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 yes and the script above will do that!! download.php?file=videos/video.mp4 $_GET['file'] and create the mySQL entry..etc display averts then redirect to download.php?hash=$hash and have $_GET['hash'] for the downloads Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326629 Share on other sites More sharing options...
joshedgar Posted August 17, 2007 Author Share Posted August 17, 2007 Well I'm not too good with MySQL beyond just basic form inputs. Can you please give me some code itself to help me understand how to put this all together? I can make the mysql DB/table. Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326855 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 have a MySQL database that have 3 fields file, hash, timestamp what php code do you have so far ? Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326871 Share on other sites More sharing options...
joshedgar Posted August 17, 2007 Author Share Posted August 17, 2007 Just to clarify, the above code currently takes http://www.pspstop.net/vip.php?path=music&filename=greenday.rar And turns it into http://www.pspstop-vip.info/vip_files/music/greenday.rar I just want to have temporary links so they dont actually see that direct link, but a randomly generated temporary one. <?php // PSPStop Anti-Leech Script by Josh Edgar $source = $_GET['source']; $parseURL = "/"; $pspstopURL = "http://www.pspstop-vip.info/vip_files"; // Do not include a slash after .info or after VIP dir name $retrieveStream = $parseURL.$_GET['path'].$parseURL.$_GET['filename']; $retrieveType = $_GET['cat']; $retrieveFile = $_GET['filename']; $fullDirectStream = $pspstopURL.$parseURL.$_GET[path].$parseURL.$_GET[filename]; $fullRecordStream = $_GET[path].$parseURL.$_GET[filename]; $vipStream = "http://www.pspstop.net/vip.php"; $startVars = "?"; $splitVars = "&"; $getRefURL = $_GET['ref']; /* Write info to a log */ // Open the file for writing. $theFile = "LOGS/vip_log.html"; $fh = fopen($theFile, 'a') or die("Failed to open file for writing."); // Preparing the string data // IP ADDRESS $ipdomain = GetHostByName($REMOTE_ADDR); // Compiling the string data. $string1 = "\n<font face='Verdana' size='2'><a href='http://whois-search.com/whois/" . $ipdomain . "'><b>" . $ipdomain . "</b></a>: "; $string2 = $fullRecordStream . "<BR></font>"; $stringData = $string1.$string2; // Write the string data to the file! fwrite($fh, $stringData); fclose($fh); ?> <meta http-equiv="Refresh" content="0; URL=<?php echo $pspstopURL.$parseURL.$_GET[path].$parseURL.$_GET[filename]; ?>" /> <html> <head> <script language="JavaScript" type="text/javascript"> <!-- var sec = 01; // set the seconds var min = 00; // set the minutes function countDown() { sec--; if (sec == -01) { sec = 59; min = min - 1; } else { min = min; } if (sec<=9) { sec = "" + sec; } time = (min<=9 ? "" + sec : sec) + ""; if (document.getElementById) { document.getElementById('theTime').innerHTML = time; } SD=window.setTimeout("countDown();", 1000); if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); } } window.onload = countDown; // --> </script> <style type="text/css"> <!-- .timeClass { font-family:verdana; font-weight:bold; font-size:10pt; } --> </style> <title>PSPStop.net - Downloading: <?php echo $retrieveFile; ?></title> <style type="text/css"> td.maina { background: url('http://www.pspstop.net/Themes/PSPTheme/images/head_bg.gif') repeat-x; height: 110px; width: 30%; } td.mainb { background: url('http://www.pspstop.net/Themes/PSPTheme/images/head_bg.gif') repeat-x; height: 110px; width: 70%; } </style> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#313233"> <table width="100%" align="center" border="0" padding="0" cellspacing="0" cellpadding="0"> <tr> <td class="maina"> <img src="http://www.pspstop.net/Themes/PSPTheme/images/logo.gif" border="0" alt="PSPSTOP.NET" /> </td> <td class="mainb" valign="center"> <CENTER><font face="Verdana" size="2" color="#FFFFFF"> Your file should begin immediately, VIP member...<br> If it does not, please <a href="<?php echo $pspstopURL.$parseURL.$_GET[path].$parseURL.$_GET[filename]; ?>">click here</a> </font></CENTER> </td> </tr> </table><br /><br /> <CENTER> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/65406-temporary-link-script/#findComment-326977 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.