也许您可以只存储路径服务器端并让前端在项目被“喜欢”后将特殊代码传递给远程端点。
$([however you're binding to the like button]).on('click', function() {
$.getJSON('/download_link.php', {'key': <some unique key>}, function(response) {
if(response.status == 'valid') {
$('<div><a href="' + response.path + '">Download the item now!</a></div>').appendTo('body');
}
else {
alert('invalid security key');
}
});
});
如果您担心人们很容易看到常规,请转到打包程序(http://dean.edwards.name/packer/)。它不安全,但它会阻止您的普通 joe 轻松查看代码。
仅供参考,打包时上面的代码如下所示:
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$([m h\'9 e l 2 5 6]).7(\'8\', 3() {\n $.b(\'/c.d\', {\'1\': <f g 1>}, 3(0) {\n i(0.j == \'k\') {\n $(\'<4><a n="\' + 0.o + \'">p 2 q r!</a></4>\').s(\'t\');\n }\n u {\n v(\'w x 1\')}})});',34,34,'response|key|the|function|div|like|button|on|click|re||getJSON|download_link|php|binding|some|unique|you|if|status|valid|to|however|href|path|Download|item|now|appendTo|body|else|alert|invalid|security'.split('|'),0,{}))
您需要从download_link.php
文件中返回以下内容:
<?php
if(valid_key($_REQUEST['key'])) {
header('Content-Type: application/json');
echo json_encode(array('status' => 'valid', 'path' => generate_secret_path()));
}
?>
希望有帮助。