To avoid this type of problems, and for best practice, i advice to use the root path:
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
The code above will assign to $root your realpath on the server.
After that just use the require/include etc according to your localhost/webserver root :
For example, if your file is located in websiterootfolder/php/nice_folder
Your code will be :
By using this practice, you can include any file from whatever position and any way you want, dynamic or not
solved PHP require_once ‘………..’;