Jump to content

How to get WHMCS System URL inside module?


weelow

Recommended Posts

Hello,

I was looking for a fast way to do this, and came across the below thread, which is closed now and the original poster did not mention how he did it using global $CONFIG.  I am going to describe how it can be done with a way other than directly accessing the database.

In the below URL it describes how you can get the base url where WHMCS is installed

Spoiler

\WHMCS\Utility\Environment\WebHelper::getBaseUrl()

Refrence: https://docs.whmcs.com/WHMCS_Base_URL_Template_Variable

This displays retrives the base url only so if this is the link to your whmcs https://www.yourdomain.com/whmcfolder/ this function will display as follows in html "/whmcsfolder"

to get the complete url to display add the following:

Spoiler

$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$baseurl = \WHMCS\Utility\Environment\WebHelper::getBaseUrl();
$url = $protocol.'://'.$_SERVER['HTTP_HOST'].$baseurl;

The above $url will display as follows https://www.yourdomain.com/whmcfolder/

I hope this is useful for anyone. Additions are always welcome of course.

Have a good day

 

 

 

Link to comment
Share on other sites

I find easier and more reliable to select it from database with:

SELECT value FROM tblconfiguration WHERE setting = 'SystemURL' LIMIT 1

With HTTP_HOST in fact you are dependent on http request header that can be manipulated while SERVER_NAME is not always available (it depends on server configuration). In conclusion I always use the one in database especially for licensing scripts 😋

Link to comment
Share on other sites

Is there a faster way to get it though, i mean it should be already loaded from the database why load it again.

I am trying to find if the global $CONFIG variable can do such thing but i cant find any information about it anywhere.

Link to comment
Share on other sites

9 hours ago, weelow said:

I was looking for a fast way to do this, and came across the below thread, which is closed now and the original poster did not mention how he did it using global $CONFIG

global $CONFIG;
$URL = $CONFIG['SystemURL'];

i'd go along with Kian and get the value from the database, either using Capsule as per your linked thread or using the model.

use WHMCS\Config\Setting;
$url = Setting::getValue('SystemURL');
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated