0

I have a problem with require_once. Code:

require_once(__ROOT__.'/_3parties/adodb/adodb-lib.inc.php');

When i write the string in url it download me the file, but php doesn't include it

The full code:

ini_set('display_errors',1); error_reporting(E_ALL); 

require_once 'autoloader.php';

 echo "2";

define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/_3parties/adodb/adodb-lib.inc.php');
echo "3";

Display only 2, not 3 but any error is displayed. Please help me!

OsomA
  • 155
  • 1
  • 18
  • Echo the full path you have in require and check it against your lib path. – progsource Nov 14 '14 at 09:37
  • you are using dirname() twice – RichardBernards Nov 14 '14 at 09:38
  • Using a dirname twice is not necessarily wrong (it would be `__DIR__.'/../`). – Wrikken Nov 14 '14 at 09:41
  • __ROOT__ is /var/www/AOSSI/Site_Sondaje and the file i want to include is /var/www/AOSSI/Site_Sondaje/_3parties/adodb/adodb-lib.inc.php. The file exists on disk because if i put the path into browser start download.. – OsomA Nov 14 '14 at 09:41
  • Not all errors that are put to the output because of your (correct) `display_errors` setting will be visible in your browser. That is why it is always recommended to enable error logging because the error log is much easier to follow. Error display is only a convenience feature for developing which most of the time works but you can have display issues with it. – hakre Nov 23 '14 at 13:33

2 Answers2

1

You should use the proper include for adodb:

require_once(__ROOT__.'/_3parties/adodb/adodb.inc.php');

In the file you are trying to include, the following line makes sure execution is halted:

if (!defined('ADODB_DIR')) die();

Complete example:

ini_set('display_errors',1); error_reporting(E_ALL); 

require_once 'autoloader.php';

 echo "2";

define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/_3parties/adodb/adodb.inc.php');
echo "3";
RichardBernards
  • 3,146
  • 1
  • 22
  • 30
  • The problem is that i am in folder _classes and i try to include something from '_3parties' which is on the same level as folder '_classes'. The __ROOT__ cannot help me because it gives me the path with '_classes' – OsomA Nov 14 '14 at 11:19
  • I have updated the answer with a complete example code... this should work (works for me anyway) – RichardBernards Nov 14 '14 at 12:15
-1

You are using dirname() twice when setting the ROOT

ini_set('display_errors',1); error_reporting(E_ALL); 

require_once 'autoloader.php';

 echo "2";

define('__ROOT__', dirname(__FILE__));
require_once(__ROOT__.'/_3parties/adodb/adodb-lib.inc.php');
echo "3";
RichardBernards
  • 3,146
  • 1
  • 22
  • 30
  • Now i receive the next message: Warning: require_once(/var/www/AOSSI/Site_Sondaje/_classes/_3parties/adodb/adodb-lib.inc.php): failed to open stream: No such file or directory in /var/www/AOSSI/Site_Sondaje/_classes/config.php on line 11 Fatal error: require_once(): Failed opening required '/var/www/AOSSI/Site_Sondaje/_classes/_3parties/adodb/adodb-lib.inc.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/AOSSI/Site_Sondaje/_classes/config.php on line 11 – OsomA Nov 14 '14 at 09:42
  • @OsomA Is there a die() statement being executed in the adodb-lib.inc.php file? Where can I find sourcecode of the file online? – RichardBernards Nov 14 '14 at 09:45
  • "twice" --- so? `dirname` if necessary might be even called 3 times. – zerkms Nov 14 '14 at 09:45
  • @RichardBernards you can download library from http://adodb.sourceforge.net/ – OsomA Nov 14 '14 at 09:52