By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Registered users only can download

100+
P: 150
I need php code that deny any user to download the files in the site except the registerd users can download the files how can i do that with php or any language?
Dec 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: 30
I need php code that deny any user to download the files in the site except the registerd users can download the files how can i do that with php or any language?
In what way are the users logged in? sessions or cookies? either way this might help:


[PHP]//the blank space is where it changes depending on sessions or cookies.
if( _______ != ''){
$logged_in = 'true';
}else{
$logged_in = 'false';
}


//in the body where ever the download link is
<?php
if($logged_in){ echo '<a href="http://mysite.com/donwload/file.zip">Download</a>';}
?>[/PHP]
Dec 13 '07 #2

Markus
Expert 5K+
P: 6,050
In what way are the users logged in? sessions or cookies? either way this might help:


[PHP]//the blank space is where it changes depending on sessions or cookies.
if( _______ != ''){
$logged_in = 'true';
}else{
$logged_in = 'false';
}


//in the body where ever the download link is
<?php
if($logged_in){ echo '<a href="http://mysite.com/donwload/file.zip">Download</a>';}
?>[/PHP]
TRUE, FALSE or NULL should never be writtin within qoutes - unless you want the TRUE, FALSE or NULL to breated treated as text.

Doing what you have done
[php]
$logged_in = 'true'
//wont check for boolean TRUE or FALSE
//but will assign the text 'true' to that variable

$logged_in = true;
//however, will give the variable a booleab TRUE.
[/php]
Dec 13 '07 #3

Post your reply

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