-1

I currently have a file class.main.php here: app/main/class/class.main.php

session.php is located in app/main/session.php

class.user.php is located in app/main/class/class.user.php

The first few lines of class.main.php include:

require_once("../../session.php");
require_once("../../../class.user.php");

The statements do not seem to work, I feel like it is a problem with the ../../

How can I correctly require these files when they're in different directories?

  • 3
    Possible duplicate of [PHP include relative path](https://stackoverflow.com/questions/17407664/php-include-relative-path) – Progman Jul 21 '18 at 12:06

2 Answers2

0

realpath() expands all symbolic links and resolves references to /./, /../ and extra / characters in the input path and returns the canonicalized absolute pathname.

Referrer : http://php.net/manual/en/function.realpath.php

Example

require_once realpath('.').'/yourfolder/session.php';

realpath('.') returns the main index.

Output :

/myhttpdfolder

Özgür Can Karagöz
  • 1,039
  • 1
  • 13
  • 32
-1
require_once("../session.php");
require_once("class.user.php");

As class.user.php is in the same folder you can access it directly be name and session.php is in main folder so you can access it like i mentioned above.

I hope it works for you!

Salvatore
  • 1,435
  • 1
  • 10
  • 21