473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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?
Mar 13 '08 #1
5 2778
Markus
6,050 Expert 4TB
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($_SESSION['logged_in']))
{
// code for download page
# require("download.php");
}
else
{
// user isn't logged in
# require("log_in.php");
}
[/php]
Any questions?
Mar 13 '08 #2
but what happens if they type the file url directly into the browser?
Mar 13 '08 #3
Markus
6,050 Expert 4TB
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).
Mar 13 '08 #4
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....didnt 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
Mar 13 '08 #5
Markus
6,050 Expert 4TB
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 :)
Mar 13 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Stanley | last post by:
Hi, I'd like to write a HTML page which can help me directly log in my Yahoo!mail or Gmail account without typing user name and password. Basically, I want to set up a link, click it and pop up...
2
by: Jeff | last post by:
Hi, I'm trying to automate a login and file download process. This occurs over the web. I have the code that opens Internet Explorer and navigates to the website. The first page that comes up...
9
by: buran | last post by:
Dear ASP.NET Programmers, How can I post data to an ASP.NET login page and pass authentication? The login page uses forms authentication, users must supply usernames and password and have to...
4
by: Bennett Haselton | last post by:
If I add this to my web.config file: <authentication mode="Forms"> <forms name=".ASPXUSERDEMO" loginUrl="login.aspx" protection="All" timeout="60" /> </authentication> I can configure the...
7
by: seberino | last post by:
How make a Python script 1. login 2. type password & 3. download file all from a **remote web site**? I'm not comfortable with *MY* software handling the password part.
2
by: seberino | last post by:
I finally figured out how to use the wonderful module urllib to download files. What if web page requires you to fill out a form with login and password first? Is this just like any other...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
9
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
Where can I get a sample login page with all functionalities (such as checking the password in the database, create cookies, check security and so forth). Code in C# would be fine. It it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.