Jump to content

Recommended Posts

I have a file outside of the site root folder containing the password to connect to mysql that is being saved in a function, which is being included in my custom cms_class.php. Now my cms_class.php file is going to be included into a few other files including the main index.php file. Now we know when using relatives path is a big no no when including a file that has already included a file. So whats the successful way to do this.

 

my directory looks something like this:
/x/server/www <--- siteroot

/x/server/www/cms/cms_class.php
/x/server/www/index.php <-- main index a.k.a Home file
/x/server/pass.php

 

pass.php ---->includes into -->cms_class.php---->includes into --->index.php

                                                                       ---->includes into ---> (random files in different folders)    

im also including the pass.php file into phpmyadmin and other config files so i can change passwords from one file that is secured. (at least i think it is since its outsite of the siteroot folder)
/x/server/apps/phpmyadmin/config.inc

the reason for me doing this is just to protect the password to connect to my databases. If someone knows another way, better or not please let me know since im always interested in different methods when it comes to passwords protections, but i still want to know what will be the right way to include these files since i'm going to be doing something similar later with different files.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/285095-relativeabsolute-paths-including-files/
Share on other sites

You can get a file's directory by using the __DIR__ magic constant. With this you can include a file with a path relative to that file regardless of if it is itself included else where.

 

eg:

require_once __DIR__.'/../blah.php';
If that line were located in a file saved at /var/www/htdocs/example.php then it would always include /var/www/blah.php regardless of where example.php was initially included from (or if it were run directly)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.