-2

I always use require('dbc.php'); to include file but what is the difference when I prefix 2 dots ../ as below, is there is any extra security.

require('../dbc.php');
require('../lib/bootstrap.php');
require_once '../../../conf/config.php';
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
Lohith
  • 47
  • 1
  • 5
  • It simply means one directory out of the present directory . With every `../` you move out by one directory this is very basic to all operating systems windows , Linux and Unix systems. – Black Mamba Sep 04 '17 at 04:31

3 Answers3

0

The . gives you the ability to set the path of the included files relatively to the path of the original file that run (the file that included them). The ./ indicates the current directory. So if including a file like such:

require('./config.php')

You are telling PHP to look in the current directory for "config.php". Which is the same as

require('config.php')

The ../ indicates the directory above or "parent directory"

require('../dbc.php');

This is telling PHP to go one directory up and look for "dbc.php".

These commands can be chained like so:

require('../lib/bootstrap.php');
require_once '../../../conf/config.php';
Sreejith BS
  • 1,183
  • 1
  • 9
  • 18
0

If you do

../../

You've gone back two directory

 ../

You've gone back one directory

This basically going out the current directory the file u are working on is in. It depends on the location of the db file relative to the file that needs it. It has nothing to do with security.

diagold
  • 493
  • 1
  • 7
  • 28
0

The dots simply are used to traverse the directory structure. What is double dot(..) and single dot(.) in Linux?, though you should avoid using relative paths and use absolute paths. Absolute vs. relative paths.

Security: In its self, it introduces no security benefits, except if you get it wrong your app won't work at all!

It does add some protection against code disclosure if PHP fails to parse. This applies ONLY if you store your main code outside of the webroot, though I have never encountered or seen this issue spontaneously happen, though it possibly could. Storing script files outside web root.

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106