Una alternativa es usar constantes mágicas, p. __DIR__
, consulte Constantes predefinidas
.
.
├── config.ini
└── public_html
├── elements
│ └── includes
│ └── db.php
├── index.php
└── secure
└── index.php
public_html/elements/includes/db.php
<?php
$config = parse_ini_file(
__DIR__ . '/../../../config.ini'
);
public_html/index.php
<?php
include __DIR__ . '/elements/includes/db.php';
public_html/seguro/index.php
<?php
include __DIR__ . '/../elements/includes/db.php';
Nota:recomiendo usar require
en lugar de include
, consulte requerir
.