how this can be implemented using php???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

how this can be implemented using php???

Post by claws »

hi.. everyone..

what i want to do is I want to give users a download link only if he is logged in.
I mean to say. say..
if the link is http://somedomailn.net/samplevideo.avi
then if once the user logged and gets the link.
he can pass it to any of his friend who is not registered member of my site(not even related to my site) then that friend can download the video.

I have 2 ways in my mind.

1. the file name should be variable( this is a bad. and stupid method)

2. instead of giving the user download link. I will give him link to a php script which will interface between user and file. I mean that script will act like a proxy for the file. and checks if the session variables(for login) are set. and if set then streams the file(which is some where on server) other wise says that you are not logged in.
advantages: problem is solved. and download accelerators cannot be used.(since its my script which is splitting the file into chunks and sending. so speed is controlled by me. am i right???)

disadvantages: inceasing load on my server. my server's cpu has to do a lot of work

no my questions are..
1. How to implement my second idea using php. any tutorial?? or links?? pls..
2. Are there any other methods?? through which this can be done.
3. How does the rapidshare/gmail work?? (because problem is same..)
4. In my 2nd method does really download accelerators are disabled???
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

1. Send download header()s. Read the file: file_get_contents() or readfile().
2. Many other methods. HTTP Message Digest, for example. Your second example is probably the most practical way of going about your problem, though.
3. Not familiar with that.
4. I'd imagine download accelerators/managers would not be affected, because a download is a download. Just because you're sending it through a script doesn't make it different than a direct download.

Other thoughts:

I'm not sure reading a file to a client will use that much cpu. (I know file_get_contents() has support for memory mapping techniques). If anything, it will be your bandwidth that will be eaten up. (this is just a guess, i've never tested it).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: how this can be implemented using php???

Post by Rovas »

claws wrote: I have 2 ways in my mind.

1. the file name should be variable( this is a bad. and stupid method)

2. instead of giving the user download link. I will give him link to a php script which will interface between user and file. I mean that script will act like a proxy for the file. and checks if the session variables(for login) are set. and if set then streams the file(which is some where on server) other wise says that you are not logged in.
advantages: problem is solved. and download accelerators cannot be used.(since its my script which is splitting the file into chunks and sending. so speed is controlled by me. am i right???)
1. You use a script file that checks that the user is logged (a boolean value that you put in the session), that filename that the script uses exists http://www.php.net/manual/en/function.file-exists.php, use basename http://www.php.net/manual/en/function.basename.php then readfile(path) then put the headers
Some browsers ignore or misread content headers so check in each one the mechanism.
A few links
search this forum
http://www.goodphptutorials.com/track/205
http://www.hotscripts.com if you want a script done by someone else
Post Reply