Include a file from different directions using the same code?

+1 Jonas Meise · August 6, 2015
Hey guys :)

I am currently programming on my website and ran into a problem while trying to make a separate file for mysql server connection.

My goal is that I have that mysql connect file and I can include that wherever I need to connect to the server. The problem which occured to me was that I included that file into another file (login class file) and this login class file is also included somewhere else in the aboutme page file.

the file tree would look something like that:


aboutme.php  //this file includes login_class.php




   login_class.php // this file includes mysql_connect.php

   login.php // this file also includes login_class.php



So the code which I used to include the mysql file looks like that:


The problem with this is that if I write it with two points at the beginning it will work for the login.php but when it has two points and you are navigating on the aboutme page it won't work since it goes back one directory too far.
So my question:
Is there a way of having an absolute path for that so it works on both pages but still having a relative root directory so I don't have to change the files whenever I wanna move the files from my localhost to the actual online server?

Post a Reply


Oldest  Newest  Rating
0 Jonas Meise · August 11, 2015
I am lazy :P
0 nmelssx nmelssx · August 11, 2015
Why don't you just update your codes on the web server? In my honest opinion, it's a lot easier that way. 
0 Jonas Meise · August 10, 2015
Oh okay thanks :)
Works when I use that server document root thing :D

Thanks for taking time to answering me :)
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.