Error while trying to include external php file in functions.php or header.php
-
If I put following codes in any template file, it does work perfectly;
require("shop/dbconnect.php"); $totalitems = count ($_SESSION['cart']['products']) + count ($_SESSION['cart']['addons']) + count ($_SESSION['cart']['domains']); if($totalitems > 0){ echo '</br><b>You have ' . $totalitems . ' item</b></br>'; } else { echo '</br><b>You have no item</b></br>'; }But when I try to put this in a shortcode, I get error. Here is the code, I put in functions.php
function ex_whmcs(){ require("shop/dbconnect.php"); $totalitems = count ($_SESSION['cart']['products']) + count ($_SESSION['cart']['addons']) + count ($_SESSION['cart']['domains']); if($totalitems > 0){ echo '</br><b>You have ' . $totalitems . ' item</b></br>'; } else { echo '</br><b>You have no item</b></br>'; } } add_shortcode( 'whmcscart', 'ex_whmcs' );Now when I call the shortcode [whmcscart], it stops after executing require(“shop/dbconnect.php”);
If I remove this line ( require(“shop/dbconnect.php”); ) from functions.php and add the shortcode in template file like this:require('shop/dbconnect.php'); echo do_shortcode('[whmcscart]');Then it works perfectly.
If I add require(‘shop/dbconnect.php’); in header.php , that also stops working!
My wordpress file is on http://www.domain.com and shop is another directory where WHMCS is installed.
Can anyone help me about this?
Thanks.
The topic ‘Error while trying to include external php file in functions.php or header.php’ is closed to new replies.