Re: a download limitation script that defies logic!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Daniel Brown-5 wrote:
> 
> On Thu, Jun 26, 2008 at 8:38 AM, szalinski <barneytramble@xxxxxxxxx>
> wrote:
>>
>> I thought I'd take the time to make a download limitation script, but
>> even
>> though the idea of this script is 'simple', it 'simply' refuses to work
>> entirely properly.
> [snip!]
> 
> 
>     You do realize that the code in this block below is only accessed
> if $downloads is greater than or equal to $dl_limit_perday, correct?
> 
>>        if($has_hit_dl_limit)
>>        {
>>                if($has_hit_timeout_limit)
>>                {
>>                        $dl = false;
>>                        print('<h1>Too many downloads today!<br />');
>>                        print "Time limit: {$time_limit}<br />Last time
>> accessed: {$last_access}<br />";
>>                        print "Time to wait = $time_to_wait seconds</h1>";
>>                        exit;
>>                }
>>                else
>>                {
>>                        mysql_query("UPDATE ip_limit SET downloads = 0
>> WHERE
>> userip = '$userip'");
>>                        //$dl = true;
>>                }
>>        }
>>        else
>>        {
>>                $dl = true;
>>        }
> 
> 
>     As a result, only when it meets that condition does it set $dl to
> TRUE for the next block.
> 
>> if ($dl)
>> {
>>        mysql_query("REPLACE INTO ip_limit (userip,last_access,downloads)
>> VALUES ('$userip', NOW(), '$downloads'+1)");
>>        download_the_file();
>> }
>> else
>> {
>>        exit, etc
>> }
> 
> 
> -- 
> </Daniel P. Brown>
> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
> $59.99/mo. with no contract!
> Dedicated servers, VPS, and hosting from $2.50/mo.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

Yep, I realise it - that's exactly the bahaviour I expect...if the user has
hit the download limit, then the script uses the inner
if($has_hit_timeout_limit) stament (relating to the timeout), and keeps
doing so on each request until the timeout is over (since download value is
still over the limit for each request) - until at which point the inner if()
statement should reset the downloads to 0, and then download the file, and
increment the downloads column up by one again.
but for some reason, if i try to put $dl = true after the UPDATE (in the
inner if($has_hit_timeout_limit) statement), the download works, but the
UPDATE never happens, so i get an ever-increasing value for 'downloads' in
the db, and only 1 download, then timer, then 1 download, then timer, etc.

it really is bizarre! :(

-- 
View this message in context: http://www.nabble.com/a-download-limitation-script-that-defies-logic%21-tp18132754p18135426.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux