how to require login for file download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ukfusion
    New Member
    • Sep 2007
    • 35

    #1

    how to require login for file download

    I am using a php login system which uses sessions and a mysql database......i will have a downloads page which will only be visible if logged in....my client wants to have files on this page that can only be downloaded if logged in.

    How would i do this? so even if someone typed the file url in directly they would still have to login?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Well, when someone logs in you set a session, right? So, on the download page check to see if the session is present and if it isn't redirect to a login page.

    [php]
    if(isset($_SESS ION['logged_in']))
    {
    // code for download page
    # require("downlo ad.php");
    }
    else
    {
    // user isn't logged in
    # require("log_in .php");
    }
    [/php]
    Any questions?

    Comment

    • ukfusion
      New Member
      • Sep 2007
      • 35

      #3
      but what happens if they type the file url directly into the browser?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by ukfusion
        but what happens if they type the file url directly into the browser?
        Oh, i see what you mean.

        Well, i've not tried my hand at this much and i've not read much (anything) about this problem. But what i would do is, have the file somewhere on your server and in a database store a name for this file (in the same row store the url)
        [id - name - url_of_file]
        Now, if someone wants to download the file you supply a link to a download page and in that link you pass the name from the db. On the download page you use content-disposition to force the file download. On the same page you also change the name in the database.

        Aha, understand? (was abit rushed).

        Comment

        • ukfusion
          New Member
          • Sep 2007
          • 35

          #5
          so basically the link name and url are taken from the db.....when the file is downloaded by someone....the link name and file name change and are re-written to the db.

          what was that bit about forcing the download....did nt understand that terminology.?

          i think i could manage the file rename bit so that mite work.

          but i think the problem woudl be.....its ok for me adding a link and making the href come from the database...but my client will be uploading files and creating the links from their cms....which means it will just be a standard link.....i need someway of applying it directly to the file or something
          Last edited by ukfusion; Mar 13 '08, 12:56 PM. Reason: forgot something

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            content disposition scroll down to the part about forcing downloads.

            Can't go into the rest of your questions atm as i'm in dier need of food!

            Back in 20mins :)

            Comment

            Working...