0

today I discover problem with accessing my language file from parts of my website. My structure is here:

ROOT
|___ index.php
|___ langugages
     |___ lang.cs.php
     |___ lang.en.php
|___ php
     |___ globals.php
     |___ readDB.php
     |___ writeDB.php
     ...

In globals.php I'm including

include './languages/lang.' . $lang . '.php';

When globals.php is called from index.php - include_once 'php/globals.php';, everything is OK, but I have readDB.php, writeDB.php, which calls include_once 'globals.php'; and which are called by AJAX from index.php and in this case it including php/languages/lang.xx.php, which not exists. Do you have any idea, how to write path to lang.xx.php in right way for using it from root and from any other folder too?

I'm thinking about something like

if (./languages/lang.xx.php not exists) include ../languages/lang.xx.php;

But, is it right way?

SilentCry
  • 1,902
  • 3
  • 16
  • 23
  • 1
    I would check [this question out](http://stackoverflow.com/q/5400031) and the following [answer out](http://stackoverflow.com/a/15752693), since this is a complete mess. Here's also a [standard paths 101](http://stackoverflow.com/a/17239771) tutorial. – HamZa Nov 10 '14 at 09:33

1 Answers1

1

Answer:

set_include_path(implode(PATH_SEPARATOR, array(__DIR__, get_include_path())));
include_once __DIR__ . '/../languages/lang.' . $lang . '.php';

Now it works from any position in site tree.

SilentCry
  • 1,902
  • 3
  • 16
  • 23