DennisHermannsen Posted March 10, 2022 Share Posted March 10, 2022 Let's say you have a knowledgebase article with the following URL: https://example.com/whmcs/knowledgebase/1/Create-a-backup.html Nothing prevents anyone from linking to that page with any text, which can cause problems. Anyone could link to https://example.com/whmcs/knowledgebase/1/WHMCS-should-fix-this.html, and it would show the correct knowledgebase article, but the URL would show as "https://example.com/whmcs/knowledgebase/1/WHMCS-should-fix-this.html" instead of redirecting to the correct URL. I made this hook a while back and thought that other people might find it useful. <?php add_hook('ClientAreaPageKnowledgebase', 1, function ($vars) { // Get the current URL and create the URL that should be redirected to $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $trueURL = $vars['systemsslurl'] . 'knowledgebase/' . ($vars['kbcurrentcat']['id'] ? $vars['kbcurrentcat']['id'] : $vars['kbarticle']['id'] ). '/' . urlencode($vars['kbcurrentcat']['urlfriendlyname'] ? $vars['kbcurrentcat']['urlfriendlyname'] : $vars['kbarticle']['urlfriendlytitle']. '.html') ; // Only redirect if visitor is viewing a knowledgebase category or an article if (($vars['templatefile'] === 'knowledgebasecat' || $vars['templatefile'] === 'knowledgebasearticle') AND strpos($url,'search') === false AND strpos($url,'tag') === false) { if ($trueURL !== $url) { header('Location: ' . $trueURL); exit(); } } }); Feel free to use it or modify it how you'd like. 0 Quote Link to comment Share on other sites More sharing options...
Newton Posted February 22, 2023 Share Posted February 22, 2023 Thanks for this hook. I cannot believe WHMCS hasn't fixed that yet 😕 0 Quote Link to comment Share on other sites More sharing options...
rockhost Posted July 26, 2023 Share Posted July 26, 2023 Wow, thanks! That was easy. Is there anything similar for /announcements? It has the same flaw. It really is insane this isn't fixed yet. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted July 26, 2023 Author Share Posted July 26, 2023 @rockhost I'll see what I can do tomorrow. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted July 27, 2023 Author Share Posted July 27, 2023 @rockhost An updated version of the hook can be found here: https://github.com/DennisSkov/WHMCS-Hooks-and-Modules#prevent-spoofing-url-for-knowledgebase-and-announcement-articles 1 Quote Link to comment Share on other sites More sharing options...
rockhost Posted July 31, 2023 Share Posted July 31, 2023 That did the trick, nice work! THANKS! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.