Skip to content

Instantly share code, notes, and snippets.

@ahmedsbytes
Created May 28, 2014 12:10
Show Gist options
  • Save ahmedsbytes/b6ba759db85319d75efd to your computer and use it in GitHub Desktop.
Save ahmedsbytes/b6ba759db85319d75efd to your computer and use it in GitHub Desktop.
<?php
class plgSystemVarnish extends JPlugin
{
function onAfterRoute( )
{
$user = JFactory::getUser( );
$option = JRequest::getVar( 'option' );
if( !$user->guest || $option == 'com_users' )
{
setcookie( 'varnishbypass', 'True', time( ) + 604800, '/' );
}
else
{
setcookie( 'varnishbypass', '', time( ) - 604800, '/' );
}
}
// setting the cookie in the afterRoute event is probably adequate,
// but in an outburst of belt and braces I decided to set/unset the
// cookie on the log in and out events too. Probably unnecessary,
// but apparently harmless.
function onUserLogin( $response )
{
setcookie( 'varnishbypass', 'True', time( ) + 604800, '/' );
}
function onUserLogout( $response )
{
setcookie( 'varnishbypass', '', time( ) - 604800, '/' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment