get direct download link from URL using PHP

Discussion in 'PHP' started by Shyamin Ayesh, Dec 5, 2013.

  1. #1
    Hi,

    i need to get direct download link from php redirect URL. the original URL is

    http://www.domain.com/mp3/download.php?id=4760
    Code (markup):
    this URL finally redirect me into this when i use browser.

    http://www.domain.com/mp3/201311/song.mp3
    Code (markup):
    now i need to get the second direct URL by php providing first URL. please can you help me. thank you !
     
    Shyamin Ayesh, Dec 5, 2013 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Use get_headers() and look for the "Location" header.
     
    nico_swd, Dec 5, 2013 IP
  3. Shyamin Ayesh

    Shyamin Ayesh Active Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    76
    #3
    wow ... it's working ... thank you vert much nico ... :D
     
    Shyamin Ayesh, Dec 5, 2013 IP
  4. ByteCoder

    ByteCoder Active Member

    Messages:
    239
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    65
    #4
    nico's solution is fine but remember - there're more ways to create a redirect page so this method is not generic.

    for example, the use of a meta-tag:
    <meta http-equiv="refresh" content="0;URL= http://www.newsite.com/newurl.html">

    or a use of an htaccess file rule.

    Good luck!
     
    ByteCoder, Dec 5, 2013 IP
  5. Shyamin Ayesh

    Shyamin Ayesh Active Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    76
    #5
    it's working for my page ... i think it's working for me for now ... and i study about cURL functions yet ...
     
    Shyamin Ayesh, Dec 5, 2013 IP