Title: Error while trying to include external php file in functions.php or header.php
Last modified: August 20, 2016

---

# Error while trying to include external php file in functions.php or header.php

 *  [Sufi](https://wordpress.org/support/users/thesufi/)
 * (@thesufi)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/error-while-trying-to-include-external-php-file-in-functionsphp-or-headerphp/)
 * 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](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.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [require()](https://wordpress.org/support/topic-tag/require/)
 * [shortcode error](https://wordpress.org/support/topic-tag/shortcode-error/)
 * [WHMCS](https://wordpress.org/support/topic-tag/whmcs/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Sufi](https://wordpress.org/support/users/thesufi/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/error-while-trying-to-include-external-php-file-in-functionsphp-or-headerphp/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
