malswe
Forum Replies Created
-
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI + PHP Snippet.(original code works only on warm up)
The ESI code does not work at allForum: Plugins
In reply to: [LiteSpeed Cache] ESI + PHP Snippet.Nothing works, only on warm-up :/
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingJoining. Thanks!
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingTry it your self, add your own IP to the look-up table. And every other visit, change from your own IP to VPN back and fourth. Only visits with your own IP address should get the javascript injected.
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingHmm not sure what you mean now.
When I test “non-matching” IP’s, I use a VPN to get a random IP that is not in the look-up table.Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingBefore I test, I change one of the IP’s in the look-up table to my own IP-Address. That always triggers the pop-up when warming up the cache.
(Everything works great with LiteSpeed Cache deactivated)
It almost seems like the “non-match IP” page cache replaces the old cache of a “matched IP” cache. – And then the becomes pop-up untriggerable.Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingHmm still the same issue
add_action('litespeed_esi_load-custom_js_block', 'custom_js_block_load'); function custom_js_block_load() { $ipList = [ '192.168.0.*', '192.168.1.*', ]; $userIp = $_SERVER['REMOTE_ADDR']; $matchFound = false; foreach ($ipList as $ipEntity) { if (ipMatch($userIp, $ipEntity)) { $matchFound = true; break; } } if (!$matchFound) { return; } do_action('litespeed_control_set_nocache'); // Ensures this block isn't cached var_dump($userIp); ?> <script type="text/javascript"> window.addEventListener('beforeunload', function(e) { e.preventDefault(); e.returnValue = ''; var confirmationMessage = '?r du s?ker p? att du vill l?mna sidan?'; e.returnValue = confirmationMessage; return confirmationMessage; }); </script> <?php } function add_custom_js() { echo apply_filters('litespeed_esi_url', 'custom_js_block', 'Custom JS Block'); } add_action('wp_footer', 'add_custom_js'); function ipMatch($userIp, $ipEntity) { $userSegments = explode('.', $userIp); $entitySegments = explode('.', $ipEntity); $numSegments = count($userSegments); for ($i = 0; $i < $numSegments; $i++) { if ($entitySegments[$i] === '*') { continue; } if ($userSegments[$i] !== $entitySegments[$i]) { return false; } } return true; }
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingCan you enlight me on exactly where to add it? I am not sure. Thanks!
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingFirst visit: 192.168.0.1 (IP match – JI is injected)
Second visit: 292.168.0.1 (IP mismatch- NO JS)
Third visit: 192.168.0.1 (IP match – NO JS)?(fail)Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingSorry, could you clarify and send your code? Thanks
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingIt works the first two times:
For example:
First visit: 192.168.0.1 (IP match – pop-up is shown + cache warmed up)
Second visit: 292.168.0.1 (IP mismatch- no pop-up is shown)
Third visit: 192.168.0.1 (IP match – no pop-up is shown) (fail)Every visit after this never triggers pop-ups, even if there is an IP match.
Thanks! ??- This reply was modified 1 year ago by malswe.
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingOh sorry, here it is.
Not sure what you mean by this:
but please try keep var_dump() the $_SERVER[‘REMOTE_ADDR’] and $matchFound on different IPs first.
Forgive me, I am new to this.add_action('litespeed_esi_load-custom_js_block', 'custom_js_block_load'); function custom_js_block_load() { $ipList = [ '192.168.0.*', '192.168.1.*', ]; $userIp = $_SERVER['REMOTE_ADDR']; $matchFound = false; foreach ($ipList as $ipEntity) { if (ipMatch($userIp, $ipEntity)) { $matchFound = true; break; } } if (!$matchFound) { return; } do_action('litespeed_control_set_nocache'); // Ensures this block isn't cached ?> <script type="text/javascript"> window.addEventListener('beforeunload', function(e) { e.preventDefault(); e.returnValue = ''; var confirmationMessage = '?r du s?ker p? att du vill l?mna sidan?'; e.returnValue = confirmationMessage; return confirmationMessage; }); </script> <?php } function add_custom_js() { echo apply_filters('litespeed_esi_url', 'custom_js_block', 'Custom JS Block'); } add_action('wp_footer', 'add_custom_js'); function ipMatch($userIp, $ipEntity) { $userSegments = explode('.', $userIp); $entitySegments = explode('.', $ipEntity); $numSegments = count($userSegments); for ($i = 0; $i < $numSegments; $i++) { if ($entitySegments[$i] === '*') { continue; } if ($userSegments[$i] !== $entitySegments[$i]) { return false; } } return true; }
Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingadd_action('litespeed_esi_load-custom_js_block', 'custom_js_block_load'); function custom_js_block_load() { do_action('litespeed_control_set_nocache'); // Ensures this block isn't cached ?> <script type="text/javascript"> window.addEventListener('beforeunload', function(e) { e.preventDefault(); e.returnValue = ''; var confirmationMessage = '?r du s?ker p? att du vill l?mna sidan?'; '192.168.0.*', '192.168.1.*', ]; $userIp = $_SERVER['REMOTE_ADDR']; $matchFound = false; foreach ($ipList as $ipEntity) { if (ipMatch($userIp, $ipEntity)) { $matchFound = true; break; } } if ($matchFound) { echo apply_filters('litespeed_esi_url', 'custom_js_block', 'Custom JS Block'); } } add_action('wp_footer', 'add_custom_js'); function ipMatch($userIp, $ipEntity) { $userSegments = explode('.', $userIp); $entitySegments = explode('.', $ipEntity); $numSegments = count($userSegments); for ($i = 0; $i < $numSegments; $i++) { if ($entitySegments[$i] === '*') { continue; } if ($userSegments[$i] !== $entitySegments[$i]) { return false; } } return true; }
I removed the cookie logic, but still it does not work.
It works the first two times:
For example:
First visit: 192.168.0.1 (IP match – pop-up is shown + cache warmed up)
Second visit: 292.168.0.1 (IP mismatch- no pop-up is shown)
Third visit: 192.168.0.1 (IP match – no pop-up is shown)
Every visit after this never triggers pop-ups, even if there is an IP match.Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingHmm I still get the Javascript injected into page with non-listed IP’s.
Thanks for helping btw! ??Forum: Plugins
In reply to: [LiteSpeed Cache] ESI not workingBut then it will be cached as always true? And the Javascript will always appear?
Test it like this:
1. Set your own IP in the look-up table
2. Warm-up cache, and see the pop-up
3. Change to a random IP with a VPN
4. Visit again – If it works as it should, you should not get the pop-up. But right now the cache still delivers the pop-up.- This reply was modified 1 year ago by malswe.