Jump to content

infratl

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

infratl's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm designing a login system in which users can login and download manuals in PDF format. I created a script called "dealer.php" in the world readable web directory that calls other scripts that are in a directory called "dealers" that has an htaccess file that denies access from all. Therefore, the files in the "dealer" directory are only accessable via a script, which I'm doing through "dealer.php". My problem now is how to make the browser download a file that is in the directory "dealers/products/pdf" since the "dealers" directory is denying access from all and causing all subdirectories to do the same. In other words, how can I make a PHP script that will make the browser download a file that is in a htaccess restricted directory? I've read about using the header "content-type: application/force-download" or something similar, then using fopen with echo or just readfile to output the contents of the file to the browser. I'm not sure this is the best approach though. Any ideas would be greatly appreciated. Thanks.
  2. [!--quoteo(post=365022:date=Apr 15 2006, 05:16 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 15 2006, 05:16 AM) [snapback]365022[/snapback][/div][div class=\'quotemain\'][!--quotec--]1 ) Both parts of an AND expression are supposed to be boolean expressions evaluating to true or false. die() returns void. [/quote]Well, wouldn't the same be true about an OR expression? Both parts are supposed to be boolean expressions. However, in the php manual, especially with the mysql functions, there are lots of examples like this one taken from [a href=\"http://us3.php.net/manual/en/function.mysql-fetch-array.php\" target=\"_blank\"]http://us3.php.net/manual/en/function.mysql-fetch-array.php[/a] : <?php mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error()); ...... [!--quoteo(post=365022:date=Apr 15 2006, 05:16 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 15 2006, 05:16 AM) [snapback]365022[/snapback][/div][div class=\'quotemain\'][!--quotec--]2 ) Both parts should be evaluated to see if the whole expression gives true or false, therefore one would expect the die() to be executed in all cases. [/quote]I don't think this is true because according to the manual AND and OR epressions are short-circuited. Meaning that, in an AND expression, if the first part is false, php won't evaluate the second part because, even if it did, the whole expression is already false. The same is true with the OR expression. If the first part is true, php won't evaluate the second part, because the whole expression is already true. [!--quoteo(post=365022:date=Apr 15 2006, 05:16 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 15 2006, 05:16 AM) [snapback]365022[/snapback][/div][div class=\'quotemain\'][!--quotec--]I can only assume that this works only because of current deficiency in the PHP processor and shouldn't be relied upon, apart from being virtually unreadable to anyone having to maintain your code. [/quote]I don't think it's a deficiency as php was, again according to info in the manual, designed to have the short-circuit or lazy evaluation feature. I do agree that it is pretty unreadable though. A programmer that's not used to seeing code written that way would probably take long to figure out what's going on.
  3. ok, let me change up the example a bit like this: say i have some code that reads: <?php if(file_exists($filename)) die('File already exists'); ?> couldn't i simply write it as: <?php file_exists($filename) and die('File already exists'); ?> wouldn't these two produce the same results? is there an advantage or disadvantage of using one over the other? i know the if condition is more readable than the and. but as far as performance and correctness of code how do they compare?
  4. hi, i came across this question recently. I often use conditional statements like: <?php [b]if[/b] (opendir($newdir)) {die('Directory already exists');} ?> could i write that condition in this form: <?php opendir($newdir)) [b]and[/b] die('Directory already exists'); ?> what would be better performance-wise or what would be more appropriate coding? i've always used the [b]if[/b] construct, but i'm curious about the [b]and[/b] construct since the manual uses [b]or die[/b] in several cases. what's the difference between using the "statement1 [b]and[/b] statement2" instead of "[b]if[/b](statemente1) {statement2}"? i know the above example is bad because i should really use file_exists() to test for the existence of the directory. however, if i were to do it with opendir, which one should i use, the [b]if[/b] or the [b]and[/b], and why?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.