In This Tutorial:
Create PHP File Add PHP Code Create Template File Add HTML Code
WHMCS is a system designed to automate and manage many common web hosting tasks for resellers. For instance, WHMCS can handle the point of sale, billing, and setup of a new account, including provisioning it on the server.
WHMCS creates pages based on the modules that are installed and the functions that are enabled by the administrator/webmaster. If you want to create a unique client area page, you can manually create the necessary .php and .tpl files to build a custom page. By completing this guide, you can learn how to create a custom page that is compatible with WHMCS.
Create a PHP (.php) File
First, a .php file needs to be created. This file will reside in your WHMCS root directory.
NOTE: If you are unsure of the location of your WHMCS installation, click the button below for additional help.
How to Locate Your WHMCS Root Directory
To locate your WHMCS directory root directory, find the document root directory for your domain. If your WHMCS root directory is also the document root directory for your website (ie. you access the website using just your domain https://www.example.com/
), then you should see the following directories inside of your document root directory for your domain:
- admin
- assets
- attachments
- downloads
- feeds
- inclues
- lang
- modules
- oauth
- pipe
- resources
- status
- templates
- templates_c
- vendor
Still unsure? The WHMCS directory will also include many .php files. Try openning a few .php files. You can identify files related to WHMCS by comparing the first few lines in the file with the code similar to the following example:
<?php //ICB0 56:0 71:ac9e ?><?php //00ee8 // ************************************************************************* // * * // * WHMCS - The Complete Client Management, Billing & Support Solution * // * Copyright (c) WHMCS Ltd. All Rights Reserved, * // * Version: 7.5.0 (7.5.0-release.1) * // * BuildId: a354371.338 * // * Build Date: 02 Apr 2018 * // * * // ************************************************************************* // * * // * Email: [email protected] * // * Website: https://www.whmcs.com * // * * // ************************************************************************* // * * // * This software is furnished under a license and may be used and copied * // * only in accordance with the terms of such license and with the * // * inclusion of the above copyright notice. This software or any other * // * copies thereof may not be provided or otherwise made available to any * // * other person. No title to and ownership of the software is hereby * // * transferred. * // * * // * You may not reverse engineer, decompile, defeat license encryption * // * mechanisms, or disassemble this software product or software product * // * license. WHMCompleteSolution may terminate this license if you don't * // * comply with any of the terms and conditions set forth in our end user * // * license agreement (EULA). In such event, licensee agrees to return * // * licensor or destroy all copies of software upon termination of the * // * license. * // * * // * Please see the EULA file for the full End User License Agreement. * // * * // *************************************************************************
NOTICE: For our example, the URL for WHMCS is: https://www.example.com/whmcs. The directory (aka: document root) on the server for https://www.example.com is: public_html/ and the WHMCS root directory is located at: public_html/whmcs/ on the server.
WHMCS pages are implemented from .php files. Later in this guide, you can learn the code to enter into the file. However, in this section, you can learn the steps to take to create the necessary .php file to add a custom page to WHMCS.
- Log into your reseller cPanel.
- Navigate to the File Manager.
- Navigate to your WHMCS root directory.
- Click the File button.
- In the pop-up, enter the name you would like to give to the file, for example
mypage.php
into the New File Name: field. - Click the Create New File button.
Add the PHP Code
Once you have created a new .php file, you will need to enter some code into it. This code is obtained from WHMCS’s Support Documentation directly. For more information on the code, you can refer to their documentation. However, this code contains the “skeleton” of a page for WHMCS. In this section, you can learn how to enter the necessary code into the mypage.php
file, created in the previous section.
- Log into your reseller cPanel.
- Click on File Manager.
- Navigate to your WHMCS root directory.
- Open the .php file you created in the previous section. To open the file, right-click on it, then click Edit.
NOTICE: If a pop-up is displayed regarding the encoding of the file, simply click the Edit button to proceed to open the file with the default encoding.
- Copy– CTRL + C (on Mac: COMMAND + C) and paste– CTRL + V (on Mac: COMMAND + V) the following code into the file. Please note that this code is commented out so that it displays properly in WordPress; you will need to remove the
!--
from the opening PHP tag when you are ready to use this code.<!--?php use WHMCSClientArea; use WHMCSDatabaseCapsule; define('CLIENTAREA', true); require __DIR__ . '/init.php'; $ca = new ClientArea(); $ca--->setPageTitle('Your Page Title Goes Here'); $ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname')); $ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name'); $ca->initPage(); //$ca->requireLogin(); // Uncomment this line to require a login to access this page // To assign variables to the template system use the following syntax. // These can then be referenced using {$variablename} in the template. //$ca->assign('variablename', $value); // Check login status if ($ca->isLoggedIn()) { /** * User is logged in - put any code you like here * * Here's an example to get the currently logged in clients first name */ $clientName = Capsule::table('tblclients') ->where('id', '=', $ca->getUserID())->pluck('firstname'); // 'pluck' was renamed within WHMCS 7.0. Replace it with 'value' instead. // ->where('id', '=', $ca->getUserID())->value('firstname'); $ca->assign('clientname', $clientName); } else { // User is not logged in $ca->assign('clientname', 'Random User'); } /** * Set a context for sidebars * * @link https://docs.whmcs.com/Editing_Client_Area_Menus#Context */ Menu::addContext(); /** * Setup the primary and secondary sidebars * * @link https://docs.whmcs.com/Editing_Client_Area_Menus#Context */ Menu::primarySidebar('announcementList'); Menu::secondarySidebar('announcementList'); # Define the template filename to be used without the .tpl extension $ca->setTemplate('mypage'); $ca->output();
- Click on the Save Changes button.
Create a Template (.tpl) File
Now that you have created the necessary .php file, you can create a .tpl file. This file will be where you can save your HTML to design the custom page you are creating for WHMCS. In this section, you can learn how to create the necessary .tpl file to design a custom page in WHMCS.
- Log into your reseller cPanel.
- Click on the File Manager icon.
- Navigate to the following directory inside of your WHMCS root directory: templates/name-of-template//
NOTE: Be sure to replace name-of-template/ with the actual directory name for your active template.
- Click the File button.
- In the pop-up, enter the name you would like to give to the file, for example
mypage.tpl
into the field New File Name:. - Click the Create New File button.
Add HTML
Once you have a .tpl file and a .php file for your custom page, you may begin desiging the page using HTML. In this section, you can learn how to add the HTML to your .tpl file and preview your page in your web browser.
- Log into your reseller cPanel.
- Click on the File Manager icon.
- Navigate to the following directory inside of your WHMCS root directory: templates/name-of-template//
NOTE: Be sure to replace name-of-template/ with the template’s directory name for your active template.
- Right-click on the .tpl file you created and select Edit.
NOTE: If a pop-up is displayed regarding the encoding of the file, simply click the Edit button to proceed to open the file with the default encoding.
- Now enter your HTML. For example:
<h3>This is my custom WHMCS page's content</h3> <p>I used the code found <a href="https://developers.whmcs.com/advanced/creating-pages/" target="_blank" title="Click here to navigate to WHMCS Support to obtain the code needed for creating a custom page.">here</a>.</p> <p>I put that code into a file named: </p> <p><code>mypage.php</code>, which resides in the root directory (where my WHMCS is installed).</p> <p>Now, I can write HTML into the file named:</p> <p><code>mypage.tpl</code>, located in the templates/six/ directory. Any HTML I save into that file, will be displayed on my new custom page.</p>
- Once you have entered your code, click on the Save Changes button.
Once you have saved the .tpl file with the code you would like (or using our example data), you can visit the URL for that page from your web browser. Simply open your browser and visit the following URL (example format):
https://www.example.com/whmcs/mypage.php
NOTE: Be sure to replace https://www.example.com/whmcs
with your actual domain (and path) to your WHMCS root directory. Additionally, be sure to change mypage.php
to the actual name of the .php file you created (not the .tpl file).
Congratulations! You now know how to create a custom page to use with your WHMCS installation.
You need to update the mypage.php code. You have it commented out at the top “<!–?php".
Thanks for catching that! I’m guessing that was commented out in the old version of our site to prevent any conflict and we missed it when we updated.
how to make primage mypage.php as clientarea.php?
Hello! Just create the file with clientarea.php as the name, copy the code listed in the instructions, and make sure that you change the name of the .tpl file and the template to reflect the filename you are using. Hope that helps!
Hello, how to add css style an js to the page?
Hello Ghaleth A.,
Thank you for your question. Unfortunately, this question is outside of the scope of what we can assist with. I recommend contacting a developer versed in those languages to help modify the WHMCS pages to your liking.
Best Regards,
Alyssa K.
dosn’t work for me,
i did all steps and i just tested the tutorial code
Oops!
Something went wrong and we couldn’t process your request.
Please go back to the previous page and try again.
Hi mouloud,
Unfortunately, those error pages can be caused by a variety of different issues. I recommend enabling error logging to see what is causing this error. I was able to find this WHMCS documentation that outlines how to do that:
https://help.whmcs.com/m/troubleshooting/l/678235-troubleshooting-a-blank-page-oops-error-message
I hope this helps!
Best Regards,
Alyssa K.
I used these codes as well trying to create Privacy Policy and Terms of Service Pages for my WHMCS and I am getting a 404 Error with both. I have double checked and everything is in the correct directories. I can post my codes here if you can try to diagnose the error. I only have one Template so I know the .tpl file is in the correct folder and everything is named correctly.
Hello and sorry for your issue. Please contact Live Support instead of posting that data here. We don’t have access to your account from this platform.
Not working for me. All I get is the contents of the .php file. It is like it is not seeing the .tpl file. I have changed what I thought needed changing within the .php file such as replacing mypage.php with my .phps name as well as changed things in the .tpl file. .tpl file is in the templates/6/ folder and .php is in the root. 🙂 Scratchin my head.
Hi Warren – Sorry for the issue with the Custom page not working. You may want to get help through the WHMCS Community as we did not develop the product. We have tested the code used in the tutorial, and it works for us. You can post your code there and get assistance with what’s causing the issue.
Great tutorial! I finally understood what needed to be done and was able to get my page created within a few minutes. I appreciate the detailed steps. Nice Job!
Thanks for your feedback! We are glad that this article helped you out.