WHMCS Login Integration - WisTex/php-integrating-scripts-example GitHub Wiki
WHMCS
WHCMS is a billing and support system that is frequently used for web hosting and software licensing. It is flexible enough to be used for supporting and selling other types of products and services.
- https://www.whmcs.com/
- License: Proprietary
- Type: Premium
Login System Integration
Method 1: Create an Addon Module for WHMCS
If you want full integration with WHMCS, WHMCS recommends that you create an Addon Module. Major benefits of doing it this way is it is easy to distribute, install and update.
- See documentation Addon Modules at WHMCS.
Method 2: Page Completely Integrated with WHMCS (including Theme)
Alternatively, if you do not want to go the module route, you can get access to WHMCS's subsystems by creating a page within WHMCS.
- See documentation Creating Pages at WHMCS.
Method 3: Only Access Logged in User Information & Database
If you don't want to use the installed WHMCS theme for your pages and only want to see if someone is logged in, then method 3 is simplest. It still gives you access to WHMCS database subsystems, if you add some additional code (provided below).
If you include the following code in your custom PHP page, you will have access to the variables related to this script's login and user management system.
<?php
// preset variable to false in case WHMCS member check does not work.
$loggedin = false;
// check to see if user is logged into WHMCS
require("../activeuser.php");
?>
Note: This assumes your module is located in a subdirectory of WHMCS. You may have to change the path if this is not the case.
This will give you access to the following variables:
/* Available Variables
$loggedin (boolean) - is a user logged in? true or false?
$userid (integer) - the user's unique ID number
(Other variables are available.)
*/
Additional Integration
If you want to access WHMCS's database subsystem, you need to include the following code after the above code.
// uses WHMCS's connection to the database, initialized in activeuser.php
use WHMCS\Database\Capsule;
Refer to the documentation at Interacting with the Database at WHMCS for details on how to use this. This line of code is not necessary if you are only seeing if a user is logged in or not.
WHMCS uses Laravel to interact with the database.
You do not have to use this method to interact with the database, but WHMCS provides a seamless way to do so.
Use with Picé
Since Picé is designed for stand-alone pages, using method 3 above is the easiest way to integrate with WHMCS.
To use this with Picé, refer to the following instructions:
Version Notes
This code should work for the following versions:
- 7.0 and higher
- Not tested with earlier versions.
Restrictions & Pitfalls
The code may not work as expected unless:
- The custom page must be located on the same domain name.
- Ideally, the custom page should be located in the main directory or a subdirectory of WHMCS.
- This manages client logins to the client area, not admin logins to the backend.
Additional Notes
To have full access to WHMCS's variables and subsystems (including being able to access WHMCS's database), it is recommended that the custom pages be located in the WHMCS directory or one of its subdirectories.
WHMCS recommends that you create an "Addon Module" instead of creating a custom page. WHMCS also provides an API that you can use.
See the resources below for more information.
Resources
Links to additional resources.