# \[php\] include()

**URL:** <https://forum.kirupa.com/t/php-include/226937>\
**Category:** programming\
**Created:** [May 25, 2007, 5:04am UTC](https://forum.kirupa.com/t/php-include/226937 "2007-05-25T05:04:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [May 25, 2007, 5:04am UTC](https://forum.kirupa.com/t/php-include/226937/1 "2007-05-25T05:04:33Z")

</div>

I have a dilemma over the include function. My code structure is simplified to what you see below. Main.php needs $constVar, which is stored inside constants.php. Main calls page.php. Page also needs $constVar, so it must include it again. I run into errors of variable redefinition. When I attempt to use include\_once(), only either main or page gets to use $constVar.

```php

<?php
   // main.php
   include("constants.php");
   echo($constVar);

   include("page.php");
   pageCode();
?> 

```

```php

<?php
   // page.php
   function pageCode()
   {
      include("constants.php");
      echo($constVar);
   }
?>

```

```php

<?php
   // constants.php
   $constVar = 5;
?>

```
