Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter malswe

    (@malswe)

    (original code works only on warm up)

    The ESI code does not work at all

    Thread Starter malswe

    (@malswe)

    Nothing works, only on warm-up :/

    Thread Starter malswe

    (@malswe)

    Joining. Thanks!

    Thread Starter malswe

    (@malswe)

    Try 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.

    Thread Starter malswe

    (@malswe)

    Hmm 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.

    Thread Starter malswe

    (@malswe)

    Before 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.

    • This reply was modified 1 year ago by malswe.
    • This reply was modified 1 year ago by malswe.
    • This reply was modified 1 year ago by malswe.
    Thread Starter malswe

    (@malswe)

    Hmm 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;
    }
    Thread Starter malswe

    (@malswe)

    Can you enlight me on exactly where to add it? I am not sure. Thanks!

    Thread Starter malswe

    (@malswe)

    First 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)

    Thread Starter malswe

    (@malswe)

    Sorry, could you clarify and send your code? Thanks

    Thread Starter malswe

    (@malswe)

    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) (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.
    Thread Starter malswe

    (@malswe)

    Oh 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;
    }

    [ Please do not bump. ]

    • This reply was modified 1 year ago by malswe.
    • This reply was modified 1 year ago by malswe.
    Thread Starter malswe

    (@malswe)

    add_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.

    Thread Starter malswe

    (@malswe)

    Hmm I still get the Javascript injected into page with non-listed IP’s.

    Thanks for helping btw! ??

    Thread Starter malswe

    (@malswe)

    But 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.
Viewing 15 replies - 1 through 15 (of 21 total)