Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Execute PHP code inside a new cPanel template?

Discussion in 'cPanel Developers' started by nibb, Jul 14, 2018.

Tags:
  1. nibb

    nibb Well-Known Member

    Joined:
    Mar 22, 2008
    Messages:
    313
    Likes Received:
    2
    Trophy Points:
    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?
     
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,834
    Likes Received:
    85
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. nibb

    nibb Well-Known Member

    Joined:
    Mar 22, 2008
    Messages:
    313
    Likes Received:
    2
    Trophy Points:
    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.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,344
    Likes Received:
    1,852
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. nibb

    nibb Well-Known Member

    Joined:
    Mar 22, 2008
    Messages:
    313
    Likes Received:
    2
    Trophy Points:
    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.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,344
    Likes Received:
    1,852
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice