nerbert
03-04-2013, 01:47 PM
I have a member I have to suspend from time to time and during the suspension he tries registering several times a day. My plan is to cache some JavaScript on his computer to identify him and abort his registration attempts.
My other admin suggested testing for a JS variable and if it has no value use AJAX to call a PHP file whose output is treated as a JS file that will be cached. Using the headers he suggested, I created a file, cache.php, to test caching:
<?php
$farfuture = mktime(0,0,0,1,1,2030);
header("Cache-control: public",true);
header("Pragma:",true);
header("Last-modified:" . date("D, d M Y H:i:s",$farfuture) . "GMT", true);
header("Expires:" . date("D, d M Y H:i:s",$farfuture) . "GMT" , true);
header('Content-Type: text/javascript; charset=utf-8');
?>
var testVar = "test";
and I request it with AJAX in the headinclude template with this:
<script>
if(typeof testVar == 'undefined') {
var getCache = new vB_AJAX_Handler(true);
getCache.onreadystatechange(function() {
alert(getCache.handler.responseText);
});
getCache.send('cache.php');
} else {
alert('t = ' + testVar);
}
</script>
So if it fails to cache I should get "var testVar = "test";" and if it caches I should get "t = test".
It doesn't cache. Do I have a problem with my headers or is there some feature of vBulletin that prevents caching?
My other admin suggested testing for a JS variable and if it has no value use AJAX to call a PHP file whose output is treated as a JS file that will be cached. Using the headers he suggested, I created a file, cache.php, to test caching:
<?php
$farfuture = mktime(0,0,0,1,1,2030);
header("Cache-control: public",true);
header("Pragma:",true);
header("Last-modified:" . date("D, d M Y H:i:s",$farfuture) . "GMT", true);
header("Expires:" . date("D, d M Y H:i:s",$farfuture) . "GMT" , true);
header('Content-Type: text/javascript; charset=utf-8');
?>
var testVar = "test";
and I request it with AJAX in the headinclude template with this:
<script>
if(typeof testVar == 'undefined') {
var getCache = new vB_AJAX_Handler(true);
getCache.onreadystatechange(function() {
alert(getCache.handler.responseText);
});
getCache.send('cache.php');
} else {
alert('t = ' + testVar);
}
</script>
So if it fails to cache I should get "var testVar = "test";" and if it caches I should get "t = test".
It doesn't cache. Do I have a problem with my headers or is there some feature of vBulletin that prevents caching?