开发者

timer like rapidshare / hotfile

I need a timer like hotfile/rapidshare which displays a download button after the completion of a certain time. The download button will have a php link to it. How do I go about this ? Is this going to be tamper proof(if I have a noscript tag) ?

UPDATE: THANKS To Šime Vidas

I came up with

<script type="application/javascript">
fu开发者_StackOverflow中文版nction loop(d) {
    var n = +d.innerHTML;

    if ( n > 0 ) {
        d.innerHTML = n - 1;
        setTimeout(function() { loop(d); }, 1000);  
    }

    else
    window.location=<?php echo '"http://localhost/";'; ?>

}

loop( document.getElementById('time') );
</script>

Is this okay ? Can it be tampered with ? Assuming javascript is enabled.

UPDATE 2: Thanks to RAYNOS

Can any1 explain how I can perform his method using php ?


function loop(d) {
    var n = +d.innerHTML;

    if ( n > 0 ) {
        d.innerHTML = n - 1;
        setTimeout(function() { loop(d); }, 1000);  
    }
}

loop( document.getElementById('time') );

Demo: http://jsfiddle.net/LYHW7/


Can it be tampered with?

Sure! You just need to write a quick and dirty script for GreaseMonkey which sets the text in the timer to 0...

You should have some server side control before showing the link to assess the 60s have actually expired.


PS:

Assuming javascript is enabled.

So, what happens otherwise?


Anything you write on the client can be tampered with.

You need to send the server a message saying "timer start". (Ajax, postback, whatever you want)

You then need the server and the client to both count to 60. Once the client has finished have it send a message to the server requesting the file.

The server will either tell you 60 seconds has passed and send you to file or it will tell you that you have cheated and you can punish the user as and how you see fit. (redirection to google is always good).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜