Hiding Download path help

Discussion in 'PHP' started by imchandan, Jun 4, 2008.

  1. #1
    Hi all,
    my site is hosted at say www.site1.com and my mp3 files are located at www.site2.com/mp3/

    i want a user to type www.site1.com/download-file/song's name.mp3 and the file from www.site2.com/mp3/song's name.mp3 gets downloaded...
    can we do this with htaccess??? i want to hide actual file path which is www.site2.com is this case....
    what i tried on www.site1.com
    RewriteRule ^download-file/(.*)$ http://www.site2.com/download.php?f=$1 [L]

    it is working but in the download window it shows the actual URL i.e.http://www.site2.com/download.php?f=song.mp3... how can i avoid it ???
    Regards,
    Chandan
     
    imchandan, Jun 4, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You can't use htaccess because it would only apply to the domain that the user is on. If it were that easy to rewrite a file path website hijacking would be too easy.

    What you could do is use file_get_contents and use a header and content type to make the download appear as if it is coming from your website. The problem with this approach is that the file would essentially be transferred from site2 to site1, and the again to the user.
     
    jestep, Jun 4, 2008 IP
  3. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #3
    The best option would be using LeechProtect feature of your cPanel.

    If you want to do it by PHP you can do it this way.

    
    <?
    $referrer = $_SERVER['HTTP_REFERER'];
    if (preg_match("/site1.com/",$referrer)) {
          header('Location: http://www.site2.com/song/mp3deliveryscript.php?songid=xxx');
    } else {
          header('Location: site1.com');
    };
    ?> 
    Code (markup):
     
    newgenservices, Jun 4, 2008 IP