Execute PHP code inside a new cPanel template?

nibb

Well-Known Member
Mar 22, 2008
321
5
68
How do I execute PHP code inside a new cPanel template?

I tried some and it does not work. Is there something special I have to do in order to execute regular PHP code inside a template?
 

24x7server

Well-Known Member
Apr 17, 2013
1,912
99
78
India
cPanel Access Level
Root Administrator
Twitter
Hi,

What exactly you mean by inside the template. Can you elaborate more on what issue you are facing and what error does occur when you actually perform the stuff that you mentioned?
 

nibb

Well-Known Member
Mar 22, 2008
321
5
68
I mean a HTML page inside a cPanel theme. You can edit HTML files inside the default theme or another one you created. But I also need to execute some PHP code inside.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463

nibb

Well-Known Member
Mar 22, 2008
321
5
68
But it does not work. My problem is that it execute basic things like echo or a redirect but even if I use the example from here:
Guide to the LiveAPI System - PHP Class - Developer Documentation - cPanel Documentation

I get a blank page the second I put the code in the file:

// Instantiate the CPANEL object.
require_once "/usr/local/cpanel/php/cpanel.php";

// Connect to cPanel - only do this once.
$cpanel = new CPANEL();
// Get domain user data.
$get_userdata = $cpanel->uapi(
'DomainInfo', 'domains_data',
array(
'format' => 'hash',
)
);
// Perform the desired actions.

So while PHP code works in the php file, no real complex code actually works unless its very simple.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello,

Here's an example that I've verified functions on a test system:

Code:
<?php
include("/usr/local/cpanel/php/cpanel.php");  // Instantiate the CPANEL object.
$cpanel = new CPANEL();                       // Connect to cPanel - only do this once.
print $cpanel->header( "Page Heading" );      // Add the header.
?>
<?php
// List an account's certificates.
$SSL_list_certs = $cpanel->uapi(
    'SSL', 'list_certs'
);
var_dump($SSL_list_certs);
?>
<?php
print $cpanel->footer();                      // Add the footer.
$cpanel->end();                               // Disconnect from cPanel - only do this once.
?>
Can you check and verify if this example works as expected and is a better reflection of what you are attempting to do?

Thank you.