Month: November 2012

W3TC Fragment Caching MFUNC

UPDATE: Having problems? Fragment caching stopped working? See the updated article with information on using W3 Total Cache fragment caching with the new W3TC_DYNAMIC_SECURITY constant which was implemented for security reasons. W3 Total Cache is a great plugin for speeding up your WordPress website with page cache, database cache, minifying JS and CSS, object cache, content delivery network and more. A problem could arise with dynamic code and a certain part of code might be cached with W3 Total Cache which you don’t want to cache. You can use the MFUNC fragment caching in your code to prevent this. Here is an example of using W3TC MFUNC comments: <!-- mfunc CODE1 -->CODE2<!-- /mfunc --> CODE 1 above is the code to execute with W3TC enabled and the page currently cached. CODE 2 above is the code to execute with W3TC disabled or the page not cached. Of course, in the above example CODE1 and CODE2 will most likely be the same code. Say you have code like this for example: echo "This is my website"; You can implement it like this <!-- mfunc echo "This is my website cached"; --><?php echo "This is my website not cached"; ?><!-- /mfunc --> Good luck with...

Read More

MySQL: Multiple COUNT in one query with conditions

I’m still learning some tricks about MySQL as I go along and figured how to combine multiple COUNT queries into a single query returning one resultset. I wanted to specifically count on the same column/field but each count having it’s own condition on the table and then group the results by a ‘created’ date column in order to get the records for the last month (30 days). You may want to do a count on different columns or even the same column but with different conditions. To do this, you can use a condition inside the MySQL COUNT query itself using something like IF or a CASE statement. Here is a quick example: SELECT Date(`created`) AS `date`, Count(IF(`column` = 'val1', 1, NULL)) AS `count1`, Count(IF(`column` = 'val2', 1, NULL)) AS `count2` FROM `table` GROUP BY Date(`created`) ORDER BY `created` ASC; This will return a resultset with ‘date’, ‘count1’ and ‘count2’. Thus ‘count1’ is the COUNT on the column where the value is something specific and same goes for ‘count2’, just a different value. You can use different operators here to determine what you want to count on. And like I mentioned earlier, you can use alternatives like CASE instead of IF when it is more suitable. And of course you can use JOIN to include other tables into the query as...

Read More

PHP $_COOKIE variable empty

The PHP $_COOKIE variable is a reserved variable and Array in PHP which contains cookies in the browser stored by PHP, Javascript and other languages. If for any reason you are using PHP setcookie() or Javascript document.cookie to set cookies and the PHP $_COOKIE variable remains empty it might actually be a server configuration that causes this. I recently came across this and wrote a test script like this: setcookie('test', 'test', strtotime("+1 day"), '/'); print_r($_COOKIE); But printing the PHP $_COOKIE variable did nothing, just an empty Array. After doing some tests the conclusion was that Apache mod_security caused this. The mod_security can be configured to prevent cookie attacks and blocks them completely. Here is a useful article showing you the technical configurations. The solution is to turn off Apache mod_security or cookie filter configuration in it....

Read More

Stay up to date

Get one email per month with latest news. You can unsubscribe at any time


Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!