简体   繁体   中英

How to make link download temporary in php

I see mediafire.com has link download will change after a time. And how to make it

Ex: now link download http://download886.mediafire.com/xvyys416wwrg/demo.zip after a time xvyys416wwrg will be change to a random string and old link http://download886.mediafire.com/xvyys416wwrg/demo.zip will not working

You can reload a page after a certain time and give it a different URL or use JavaScript for this.

PHP solution:

session_start();

if(isset($_SESSION["some_url"]))
{
echo '<a href="/'.$_SESSION["some_url"].'/demo.zip" />Link</a>';
}
else
{
echo '<a href="/starter_url/demo.zip" />Link</a>';
}
//Here is where you give it the new url
$_SESSION["some_url"]="whateverurl123";

header( "refresh:5;url=wherever.php" );

Now the page will reload every 5 sec with whateverurl123 attached to the link. You can change that every time the page reloads.

You can achieve this without reloading the page using AJAX

Here is a little help

setInterval(function()
{ 
    $.ajax({
      type:"post",
      url:"myurl.php",
      async: false}).success:function(data){
          $('#url_div').html('<a href="/'+data["generated_url"]+'/demo.zip" />Link</a>');
      }
    });
}, 5000);//time in milliseconds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM